Documentation

CsvEncoder
in package
implements EncoderInterface, DecoderInterface

Encodes CSV data.

Tags
author

Kévin Dunglas dunglas@gmail.com

author

Oliver Hoff oliver@hofff.com

Table of Contents

Interfaces

EncoderInterface
DecoderInterface

Constants

AS_COLLECTION_KEY  = 'as_collection'
DELIMITER_KEY  = 'csv_delimiter'
ENCLOSURE_KEY  = 'csv_enclosure'
END_OF_LINE  = 'csv_end_of_line'
ESCAPE_CHAR_KEY  = 'csv_escape_char'
ESCAPE_FORMULAS_KEY  = 'csv_escape_formulas'
FORMAT  = 'csv'
HEADERS_KEY  = 'csv_headers'
KEY_SEPARATOR_KEY  = 'csv_key_separator'
NO_HEADERS_KEY  = 'no_headers'
OUTPUT_UTF8_BOM_KEY  = 'output_utf8_bom'
FORMULAS_START_CHARACTERS  = ['=', '-', '+', '@', "\t", "\r"]
UTF8_BOM  = ""

Properties

$defaultContext  : mixed

Methods

__construct()  : mixed
decode()  : mixed
Decodes a string into PHP data.
encode()  : string
Encodes data into the given format.
supportsDecoding()  : bool
Checks whether the deserializer can decode from given format.
supportsEncoding()  : bool
Checks whether the serializer can encode to given format.
extractHeaders()  : array<string|int, string>
flatten()  : mixed
Flattens an array and generates keys including the path.
getCsvOptions()  : array<string|int, mixed>

Constants

AS_COLLECTION_KEY

public mixed AS_COLLECTION_KEY = 'as_collection'

DELIMITER_KEY

public mixed DELIMITER_KEY = 'csv_delimiter'

ENCLOSURE_KEY

public mixed ENCLOSURE_KEY = 'csv_enclosure'

END_OF_LINE

public mixed END_OF_LINE = 'csv_end_of_line'

ESCAPE_CHAR_KEY

public mixed ESCAPE_CHAR_KEY = 'csv_escape_char'

ESCAPE_FORMULAS_KEY

public mixed ESCAPE_FORMULAS_KEY = 'csv_escape_formulas'

HEADERS_KEY

public mixed HEADERS_KEY = 'csv_headers'

KEY_SEPARATOR_KEY

public mixed KEY_SEPARATOR_KEY = 'csv_key_separator'

NO_HEADERS_KEY

public mixed NO_HEADERS_KEY = 'no_headers'

OUTPUT_UTF8_BOM_KEY

public mixed OUTPUT_UTF8_BOM_KEY = 'output_utf8_bom'

FORMULAS_START_CHARACTERS

private mixed FORMULAS_START_CHARACTERS = ['=', '-', '+', '@', "\t", "\r"]

Properties

$defaultContext

private mixed $defaultContext = [self::DELIMITER_KEY => ',', self::ENCLOSURE_KEY => '"', self::ESCAPE_CHAR_KEY => '', self::END_OF_LINE => "\n", self::ESCAPE_FORMULAS_KEY => false, self::HEADERS_KEY => [], self::KEY_SEPARATOR_KEY => '.', self::NO_HEADERS_KEY => false, self::AS_COLLECTION_KEY => true, self::OUTPUT_UTF8_BOM_KEY => false]

Methods

__construct()

public __construct([array<string|int, mixed> $defaultContext = [] ]) : mixed
Parameters
$defaultContext : array<string|int, mixed> = []

decode()

Decodes a string into PHP data.

public decode(string $data, string $format[, array<string|int, mixed> $context = [] ]) : mixed
Parameters
$data : string

Data to decode

$format : string

Format name

$context : array<string|int, mixed> = []

Options that decoders have access to

The format parameter specifies which format the data is in; valid values depend on the specific implementation. Authors implementing this interface are encouraged to document which formats they support in a non-inherited phpdoc comment.

encode()

Encodes data into the given format.

public encode(mixed $data, string $format[, array<string|int, mixed> $context = [] ]) : string
Parameters
$data : mixed

Data to encode

$format : string

Format name

$context : array<string|int, mixed> = []

Options that normalizers/encoders have access to

Return values
string

supportsDecoding()

Checks whether the deserializer can decode from given format.

public supportsDecoding(string $format) : bool
Parameters
$format : string

Format name

Return values
bool

supportsEncoding()

Checks whether the serializer can encode to given format.

public supportsEncoding(string $format) : bool
Parameters
$format : string

Format name

Return values
bool

extractHeaders()

private extractHeaders(iterable<string|int, mixed> $data) : array<string|int, string>
Parameters
$data : iterable<string|int, mixed>
Return values
array<string|int, string>

flatten()

Flattens an array and generates keys including the path.

private flatten(iterable<string|int, mixed> $array, array<string|int, mixed> &$result, string $keySeparator[, string $parentKey = '' ][, bool $escapeFormulas = false ]) : mixed
Parameters
$array : iterable<string|int, mixed>
$result : array<string|int, mixed>
$keySeparator : string
$parentKey : string = ''
$escapeFormulas : bool = false

getCsvOptions()

private getCsvOptions(array<string|int, mixed> $context) : array<string|int, mixed>
Parameters
$context : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results