Horde_Data_Csv extends Horde_Data_Base
Horde_Data implementation for comma-separated data (CSV).
Tags
Table of Contents
- $storage : Horde_Data_Storage
- Storage object.
- $_browser : Horde_Browser
- Browser object.
- $_cleanupCallback : callable
- Cleanup callback function.
- $_contentType : string
- MIME content type.
- $_extension : string
- File extension.
- $_http : Horde_Http_Client
- HTTP client object.
- $_vars : Horde_Variables
- Variables object.
- $_warnings : array<string|int, mixed>
- A list of warnings raised during the last operation.
- __construct() : mixed
- Constructor.
- cleanup() : mixed
- Removes any uploaded and moved files.
- exportData() : string
- Builds a CSV file from a given data structure and returns it as a string.
- exportFile() : mixed
- Builds a CSV file from a given data structure and triggers its download. It DOES NOT exit the current script but only outputs the correct headers and data.
- getContentType() : string
- Returns the content type.
- getCsv() : array<string|int, mixed>|bool
- Wrapper around fgetcsv().
- getFilename() : string
- Returns the full filename including the basename and extension.
- getNewline() : string
- Tries to determine the expected newline character based on the platform information passed by the browser's agent header.
- importData() : mixed
- Stub to import passed data.
- importFile() : array<string|int, mixed>
- Imports and parses a CSV file.
- importUrl() : mixed
- Imports a URL.
- nextStep() : mixed
- Takes all necessary actions for the given import step, parameters and form values and returns the next necessary step.
- warnings() : array<string|int, mixed>
- Returns a list of warnings that have been raised during the last operation.
- _mapDate() : string
- Maps a date/time string to an associative array.
Properties
$storage
Storage object.
public
Horde_Data_Storage
$storage
$_browser
Browser object.
protected
Horde_Browser
$_browser
$_cleanupCallback
Cleanup callback function.
protected
callable
$_cleanupCallback
$_contentType
MIME content type.
protected
string
$_contentType
= 'application/csv'
$_extension
File extension.
protected
string
$_extension
= 'csv'
$_http
HTTP client object.
protected
Horde_Http_Client
$_http
$_vars
Variables object.
protected
Horde_Variables
$_vars
$_warnings
A list of warnings raised during the last operation.
protected
array<string|int, mixed>
$_warnings
= array()
Methods
__construct()
Constructor.
public
__construct(Horde_Data_Storage $storage[, array<string|int, mixed> $params = array() ]) : mixed
Parameters
- $storage : Horde_Data_Storage
- $params : array<string|int, mixed> = array()
-
Optional parameters:
- browser: (Horde_Browser) A browser object.
- http: (Horde_Http_Client) A HTTP client object.
- cleanup: (callback) A callback to call at cleanup time.
- vars: (Horde_Variables) Form data.
Return values
mixed —cleanup()
Removes any uploaded and moved files.
public
cleanup() : mixed
Return values
mixed —If callback called, the return value of this call. This should be the value of the first import step.
exportData()
Builds a CSV file from a given data structure and returns it as a string.
public
exportData(array<string|int, mixed> $data[, bool $header = false ][, mixed $export_mapping = array() ]) : string
Parameters
- $data : array<string|int, mixed>
-
A two-dimensional array containing the data set.
- $header : bool = false
-
If true, the rows of $data are associative arrays with field names as their keys.
- $export_mapping : mixed = array()
Return values
string —The CSV data.
exportFile()
Builds a CSV file from a given data structure and triggers its download. It DOES NOT exit the current script but only outputs the correct headers and data.
public
exportFile(string $filename, array<string|int, mixed> $data[, bool $header = false ][, mixed $export_mapping = array() ]) : mixed
Parameters
- $filename : string
-
The name of the file to be downloaded.
- $data : array<string|int, mixed>
-
A two-dimensional array containing the data set.
- $header : bool = false
-
If true, the rows of $data are associative arrays with field names as their keys.
- $export_mapping : mixed = array()
Return values
mixed —getContentType()
Returns the content type.
public
getContentType() : string
Return values
string —The content type.
getCsv()
Wrapper around fgetcsv().
public
static getCsv(resource $file[, array<string|int, mixed> $params = array() ]) : array<string|int, mixed>|bool
Empty lines will be skipped. If the 'length' parameter is provided, all rows are filled up with empty strings up to this length, or stripped down to this length.
Parameters
- $file : resource
-
A file pointer.
- $params : array<string|int, mixed> = array()
-
Optional parameters. Possible values:
- escape: The escape character.
- length: The expected number of fields.
- quote: The quote character.
- separator: The field delimiter.
Return values
array<string|int, mixed>|bool —A row from the CSV file or false on error or end of file.
getFilename()
Returns the full filename including the basename and extension.
public
getFilename(string $basename) : string
Parameters
- $basename : string
-
Basename for the file.
Return values
string —The file name.
getNewline()
Tries to determine the expected newline character based on the platform information passed by the browser's agent header.
public
getNewline() : string
Return values
string —The guessed expected newline characters, either \n, \r or \r\n.
importData()
Stub to import passed data.
public
importData(mixed $text) : mixed
Parameters
- $text : mixed
Return values
mixed —importFile()
Imports and parses a CSV file.
public
importFile(string $filename[, bool $header = false ][, string $sep = ',' ][, string $quote = '' ][, int $fields = null ][, mixed $import_mapping = array() ][, string $charset = null ][, string $crlf = null ]) : array<string|int, mixed>
Parameters
- $filename : string
-
The name of the file to parse.
- $header : bool = false
-
Does the first line contain the field/column names?
- $sep : string = ','
-
The field/column separator.
- $quote : string = ''
-
The quoting character.
- $fields : int = null
-
The number or fields/columns.
- $import_mapping : mixed = array()
- $charset : string = null
-
The file's charset.
- $crlf : string = null
-
The file's linefeed characters.
Tags
Return values
array<string|int, mixed> —A two-dimensional array of all imported data rows. If $header was true the rows are associative arrays with the field/column names as the keys.
importUrl()
Imports a URL.
public
importUrl(mixed $url[, mixed $header = false ]) : mixed
Parameters
- $url : mixed
- $header : mixed = false
Tags
Return values
mixed —nextStep()
Takes all necessary actions for the given import step, parameters and form values and returns the next necessary step.
public
nextStep(int $action[, array<string|int, mixed> $param = array() ]) : mixed
Parameters
- $action : int
-
The current step. One of the IMPORT_* constants.
- $param : array<string|int, mixed> = array()
-
An associative array containing needed parameters for the current step. Keys for this driver:
- check_charset: (boolean) Do some checks to see if the correct charset has been provided. Throws charset exception on error.
- import_mapping: TODO
Tags
Return values
mixed —Either the next step as an integer constant or imported data set after the final step.
warnings()
Returns a list of warnings that have been raised during the last operation.
public
warnings() : array<string|int, mixed>
Return values
array<string|int, mixed> —A (possibly empty) list of warnings.
_mapDate()
Maps a date/time string to an associative array.
protected
_mapDate(string $date, string $type, array<string|int, mixed> $params, int $key) : string
Parameters
- $date : string
-
The date.
- $type : string
-
One of 'date', 'time' or 'datetime'.
- $params : array<string|int, mixed>
-
Two-dimensional array with additional information about the formatting. Possible keys are:
- delimiter: The character that seperates the different date/time parts.
- format: If 'ampm' and $date contains a time we assume that it is in AM/PM format.
- order: If $type is 'datetime' the order of the day and time parts: -1 (timestamp), 0 (day/time), 1 (time/day).
- $key : int
-
The key to use for $params.
Return values
string —The date or time in ISO format.