Properties

$stream_filter_mode

$stream_filter_mode : integer

The stream filter mode (read or write).

Type

integer

$stream_filters

$stream_filters : array<mixed,boolean>

collection of stream filters.

Type

array<mixed,boolean>

$input_bom

$input_bom : string|null

The CSV document BOM sequence.

Type

string|null

$output_bom

$output_bom : string

The Output file BOM character.

Type

string

$delimiter

$delimiter : string

the field delimiter (one character only).

Type

string

$enclosure

$enclosure : string

the field enclosure character (one character only).

Type

string

$escape

$escape : string

the field escape character (one character only).

Type

string

$document

$document : \SplFileObject|\League\Csv\Stream

The CSV document.

Type

\SplFileObject|\League\Csv\Stream

$is_input_bom_included

$is_input_bom_included : boolean

Tells whether the Input BOM must be included or skipped.

Type

boolean

$formatters

$formatters : array<mixed,callable>

callable collection to format the record before insertion.

Type

array<mixed,callable>

$validators

$validators : array<mixed,callable>

callable collection to validate the record before insertion.

Type

array<mixed,callable>

$newline

$newline : string

newline character.

Type

string

$flush_counter

$flush_counter : integer

Insert records count for flushing.

Type

integer

$flush_threshold

$flush_threshold : integer|null

Buffer flush threshold.

Type

integer|null

$rfc4180_regexp

$rfc4180_regexp : string

Regular expression used to detect if RFC4180 formatting is necessary.

Type

string

$rfc4180_enclosure

$rfc4180_enclosure : string

double enclosure for RFC4180 compliance.

Type

string

Methods

__destruct()

__destruct() 

{@inheritdoc}

__clone()

__clone() 

{@inheritdoc}

createFromFileObject()

createFromFileObject(\SplFileObject  $file) : static

Return a new instance from a SplFileObject.

Parameters

\SplFileObject $file

Returns

static

createFromStream()

createFromStream(resource  $stream) : static

Return a new instance from a PHP resource stream.

Parameters

resource $stream

Returns

static

createFromString()

createFromString(\League\Csv\string  $content = '') : static

Return a new instance from a string.

Parameters

\League\Csv\string $content

Returns

static

createFromPath()

createFromPath(\League\Csv\string  $path, \League\Csv\string  $open_mode = 'r+', resource|null  $context = null) : static

Return a new instance from a file path.

Parameters

\League\Csv\string $path
\League\Csv\string $open_mode
resource|null $context

the resource context

Returns

static

getDelimiter()

getDelimiter() 

Returns the current field delimiter.

getEnclosure()

getEnclosure() 

Returns the current field enclosure.

getPathname()

getPathname() 

Returns the pathname of the underlying document.

getEscape()

getEscape() 

Returns the current field escape character.

getOutputBOM()

getOutputBOM() 

Returns the BOM sequence in use on Output methods.

getInputBOM()

getInputBOM() 

Returns the BOM sequence of the given CSV.

getStreamFilterMode()

getStreamFilterMode() 

Returns the stream filter mode.

supportsStreamFilter()

supportsStreamFilter() 

Tells whether the stream filter capabilities can be used.

hasStreamFilter()

hasStreamFilter(\League\Csv\string  $filtername) 

Tell whether the specify stream filter is attach to the current stream.

Parameters

\League\Csv\string $filtername

isInputBOMIncluded()

isInputBOMIncluded() 

Tells whether the BOM can be stripped if presents.

chunk()

chunk(integer  $length) 

Retuns the CSV document as a Generator of string chunk.

Parameters

integer $length

number of bytes read

Throws

\League\Csv\Exception

if the number of bytes is lesser than 1

__toString()

__toString() 

DEPRECATION WARNING! This method will be removed in the next major point release.

getContent()

getContent() 

Retrieves the CSV content.

output()

output(\League\Csv\string  $filename = null) : integer

Outputs all data on the CSV file.

Parameters

\League\Csv\string $filename

Returns

integer —

Returns the number of characters read from the handle and passed through to the output.

setDelimiter()

setDelimiter(\League\Csv\string  $delimiter) : static

Sets the field delimiter.

Parameters

\League\Csv\string $delimiter

Throws

\League\Csv\Exception

If the Csv control character is not one character only.

Returns

static

setEnclosure()

setEnclosure(\League\Csv\string  $enclosure) : static

Sets the field enclosure.

Parameters

\League\Csv\string $enclosure

Throws

\League\Csv\Exception

If the Csv control character is not one character only.

Returns

static

setEscape()

setEscape(\League\Csv\string  $escape) : static

Sets the field escape character.

Parameters

\League\Csv\string $escape

Throws

\League\Csv\Exception

If the Csv control character is not one character only.

Returns

static

skipInputBOM()

skipInputBOM() : static

Enables BOM Stripping.

Returns

static

includeInputBOM()

includeInputBOM() : static

Disables skipping Input BOM.

Returns

static

setOutputBOM()

setOutputBOM(\League\Csv\string  $str) : static

Sets the BOM sequence to prepend the CSV on output.

Parameters

\League\Csv\string $str

Returns

static

addStreamFilter()

addStreamFilter(\League\Csv\string  $filtername, null|mixed  $params = null) : static

append a stream filter.

Parameters

\League\Csv\string $filtername
null|mixed $params

Throws

\League\Csv\Exception

If the stream filter API can not be used

Returns

static

getNewline()

getNewline() 

Returns the current newline sequence characters.

getFlushThreshold()

getFlushThreshold() : integer|null

Get the flush threshold.

Returns

integer|null

insertAll()

insertAll(\Traversable|array  $records) 

Adds multiple records to the CSV document.

Parameters

\Traversable|array $records

insertOne()

insertOne(array  $record) 

Adds a single record to a CSV document.

A record is an array that can contains scalar types values, NULL values or objects implementing the __toString method.

Parameters

array $record

Throws

\League\Csv\CannotInsertRecord

If the record can not be inserted

addFormatter()

addFormatter(callable  $formatter) 

Adds a record formatter.

Parameters

callable $formatter

addValidator()

addValidator(callable  $validator, \League\Csv\string  $validator_name) 

Adds a record validator.

Parameters

callable $validator
\League\Csv\string $validator_name

setNewline()

setNewline(\League\Csv\string  $newline) 

Sets the newline sequence.

Parameters

\League\Csv\string $newline

setFlushThreshold()

setFlushThreshold(integer|null  $threshold) 

Set the flush threshold.

Parameters

integer|null $threshold

Throws

\League\Csv\Exception

if the threshold is a integer lesser than 1

__construct()

__construct(\SplFileObject|\League\Csv\Stream  $document) 

New instance.

Parameters

\SplFileObject|\League\Csv\Stream $document

The CSV Object instance

resetProperties()

resetProperties() 

Reset dynamic object properties to improve performance.

sendHeaders()

sendHeaders(\League\Csv\string  $filename) 

Send the CSV headers.

Adapted from Symfony\Component\HttpFoundation\ResponseHeaderBag::makeDisposition

Parameters

\League\Csv\string $filename

Throws

\League\Csv\Exception

if the submitted header is invalid according to RFC 6266

addRecord()

addRecord(array  $record) : integer|false

Adds a single record to a CSV Document using PHP algorithm.

Parameters

array $record

Returns

integer|false

formatRecord()

formatRecord(array  $record, callable  $formatter) 

Format a record.

The returned array must contain

  • scalar types values,
  • NULL values,
  • or objects implementing the __toString() method.

Parameters

array $record
callable $formatter

validateRecord()

validateRecord(array  $record) 

Validate a record.

Parameters

array $record

Throws

\League\Csv\CannotInsertRecord

If the validation failed

consolidate()

consolidate() 

Apply post insertion actions.