Documentation

Reader extends AbstractCsv
in package
implements TabularDataReader, JsonSerializable

A class to parse and read records from a CSV document.

Tags
template

Table of Contents

Interfaces

TabularDataReader
Represents a Tabular data.
JsonSerializable

Constants

STREAM_FILTER_MODE  = \STREAM_FILTER_READ

Properties

$delimiter  : string
$document  : SplFileObject|Stream
$enclosure  : string
$escape  : string
$formatters  : array<string|int, callable(array<string|int, mixed>): array<string|int, mixed>>
$header  : array<string|int, string>
$header_offset  : int|null
$input_bom  : Bom|null
$is_empty_records_included  : bool
$is_input_bom_included  : bool
$nb_records  : int
$output_bom  : Bom|null
$stream_filters  : array<string, bool>

Methods

__clone()  : mixed
__toString()  : string
DEPRECATION WARNING! This method will be removed in the next major point release.
addFormatter()  : static
Adds a record formatter.
addStreamFilter()  : static
DEPRECATION WARNING! This method will be removed in the next major point release.
appendStreamFilterOnRead()  : static
Append a stream filter.
appendStreamFilterOnWrite()  : static
Append a stream filter.
chunk()  : Generator
Returns the CSV document as a Generator of string chunk.
chunkBy()  : iterable<string|int, TabularDataReader>
count()  : int
Returns the number of records contained in the tabular data structure excluding the header record.
createFromFileObject()  : static
DEPRECATION WARNING! This method will be removed in the next major point release.
createFromPath()  : static
DEPRECATION WARNING! This method will be removed in the next major point release.
createFromStream()  : static
DEPRECATION WARNING! This method will be removed in the next major point release.
createFromString()  : static
DEPRECATION WARNING! This method will be removed in the next major point release.
download()  : int
Outputs all data on the CSV file.
each()  : bool
exists()  : bool
fetchColumn()  : Iterator<int, mixed>
Returns a single column from the next record of the tabular data.
fetchColumnByName()  : Iterator
DEPRECATION WARNING! This method will be removed in the next major point release.
fetchColumnByOffset()  : Iterator
DEPRECATION WARNING! This method will be removed in the next major point release.
fetchOne()  : array<string|int, mixed>
DEPRECATION WARNING! This method will be removed in the next major point release.
fetchPairs()  : Iterator
Returns the next key-value pairs from the tabular data (first column is the key, second column is the value).
filter()  : TabularDataReader
first()  : array<string|int, mixed>
firstAsObject()  : object|null
from()  : static
Returns a new instance from a file path.
fromString()  : static
Returns a new instance from a string.
getContent()  : string
Retrieves the CSV content.
getDelimiter()  : string
Returns the current field delimiter.
getEnclosure()  : string
Returns the current field enclosure.
getEscape()  : string
Returns the current field escape character.
getHeader()  : array<string|int, string>
Returns the header associated with the tabular data.
getHeaderOffset()  : int|null
Returns the header offset.
getInputBOM()  : string
Returns the BOM sequence of the given CSV.
getIterator()  : Iterator<string|int, TValue>
Returns the tabular data rows as an iterator object containing flat array.
getObjects()  : Iterator
DEPRECATION WARNING! This method will be removed in the next major point release.
getOutputBOM()  : string
Returns the BOM sequence in use on Output methods.
getPathname()  : string
Returns the pathname of the underlying document.
getRecords()  : Iterator<string|int, TValue>
Returns the tabular data records as an iterator object.
getRecordsAsObject()  : iterator<string|int, T>
getStreamFilterMode()  : int
DEPRECATION WARNING! This method will be removed in the next major point release.
hasStreamFilter()  : bool
Tells whether the specified stream filter is attached to the current stream.
includeEmptyRecords()  : static
Disables skipping empty records.
includeInputBOM()  : static
Disables skipping Input BOM.
isEmptyRecordsIncluded()  : bool
Tells whether empty records are skipped by the instance.
isInputBOMIncluded()  : bool
Tells whether the BOM can be stripped if presents.
jsonSerialize()  : array<string|int, mixed>
last()  : array<string|int, mixed>
lastAsObject()  : object|null
map()  : Iterator<string|int, TMap>
Run a map over each container members.
mapHeader()  : TabularDataReader
matching()  : iterable<int, TabularDataReader>
EXPERIMENTAL WARNING! This method implementation will change in the next major point release.
matchingFirst()  : TabularDataReader|null
EXPERIMENTAL WARNING! This method implementation will change in the next major point release.
matchingFirstOrFail()  : TabularDataReader
EXPERIMENTAL WARNING! This method implementation will change in the next major point release.
nth()  : array<string|int, mixed>
nthAsObject()  : object|null
output()  : int
DEPRECATION WARNING! This method will be removed in the next major point release.
prependStreamFilterOnRead()  : static
Prepend a stream filter.
prependStreamFilterOnWrite()  : static
Prepend a stream filter.
reduce()  : TInitial|null
select()  : TabularDataReader
selectAllExcept()  : TabularDataReader
setDelimiter()  : static
Sets the field delimiter.
setEnclosure()  : static
Sets the field enclosure.
setEscape()  : static
Sets the field escape character.
setHeaderOffset()  : static
Selects the record to be used as the CSV header.
setOutputBOM()  : static
Sets the BOM sequence to prepend the CSV on output.
skipEmptyRecords()  : static
Enables skipping empty records.
skipInputBOM()  : static
Enables BOM Stripping.
slice()  : TabularDataReader
sorted()  : TabularDataReader
supportsStreamFilter()  : bool
DEPRECATION WARNING! This method will be removed in the next major point release.
supportsStreamFilterOnRead()  : bool
Tells whether the stream filter read capabilities can be used.
supportsStreamFilterOnWrite()  : bool
Tells whether the stream filter write capabilities can be used.
toString()  : string
Retrieves the CSV content.
value()  : mixed
__construct()  : mixed
combineHeader()  : Iterator
computeHeader()  : array<string|int, int|string>
Returns the header to be used for iteration.
getDocument()  : SplFileObject|Stream
getLastRecord()  : array<string|int, mixed>
prepareHeader()  : array<string|int, int|string>
prepareRecords()  : Iterator
removeBOM()  : array<string|int, string>
Strips the BOM sequence from a record.
resetProperties()  : void
Reset dynamic object properties to improve performance.
seekRow()  : array<string|int, mixed>
sendHeaders()  : void
DEPRECATION WARNING! This method will be removed in the next major point release.
setHeader()  : array<string|int, string>
Determines the CSV record header.
stripBOM()  : Iterator
Strips the BOM sequence from the returned records if necessary.

Constants

STREAM_FILTER_MODE

protected mixed STREAM_FILTER_MODE = \STREAM_FILTER_READ

Properties

$document read-only

protected SplFileObject|Stream $document

$formatters

protected array<string|int, callable(array<string|int, mixed>): array<string|int, mixed>> $formatters = []

collection of Closure to format the record before reading.

$header

protected array<string|int, string> $header = []

header record.

$header_offset

protected int|null $header_offset = null

$is_empty_records_included

protected bool $is_empty_records_included = false

$is_input_bom_included

protected bool $is_input_bom_included = false

$nb_records

protected int $nb_records = -1

$stream_filters

protected array<string, bool> $stream_filters = []

collection of stream filters.

Methods

__toString()

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

public __toString() : string

since version 9.1.0

use League\Csv\AbstractCsv::toString() instead

Tags
see
AbstractCsv::toString
codeCoverageIgnore

Retrieves the CSV content

Return values
string

addFormatter()

Adds a record formatter.

public addFormatter(callable(array<string|int, mixed>): array<string|int, mixed> $formatter) : static
Parameters
$formatter : callable(array<string|int, mixed>): array<string|int, mixed>
Return values
static

addStreamFilter()

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

public addStreamFilter(string $filtername[, array<string|int, mixed>|null $params = null ]) : static

since version 9.22.0

use League\Csv\AbstractCsv::appendStreamFilterOnRead() or League\Csv\AbstractCsv::prependStreamFilterOnRead() instead

Parameters
$filtername : string
$params : array<string|int, mixed>|null = null
Tags
codeCoverageIgnore
see
AbstractCsv::appendStreamFilterOnRead()
see
AbstractCsv::appendStreamFilterOnWrite()

Append a stream filter.

throws
InvalidArgument

If the stream filter API can not be appended

throws
UnavailableFeature

If the stream filter API can not be used

Return values
static

appendStreamFilterOnRead()

Append a stream filter.

public appendStreamFilterOnRead(string $filtername[, mixed $params = null ]) : static
Parameters
$filtername : string
$params : mixed = null
Tags
throws
InvalidArgument

If the stream filter API can not be appended

throws
UnavailableFeature

If the stream filter API can not be used

Return values
static

appendStreamFilterOnWrite()

Append a stream filter.

public appendStreamFilterOnWrite(string $filtername[, mixed $params = null ]) : static
Parameters
$filtername : string
$params : mixed = null
Tags
throws
InvalidArgument

If the stream filter API can not be appended

throws
UnavailableFeature

If the stream filter API can not be used

Return values
static

chunk()

Returns the CSV document as a Generator of string chunk.

public chunk(int $length) : Generator
Parameters
$length : int
Tags
throws
Exception

if the number of bytes is less than 1

Return values
Generator

count()

Returns the number of records contained in the tabular data structure excluding the header record.

public count() : int
Tags
throws
Exception
Return values
int

createFromFileObject()

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

public static createFromFileObject(SplFileObject $file) : static

since version 9.27.0

Returns a new instance from a SplFileObject.

use League\Csv\AbstractCsv::from() instead

Parameters
$file : SplFileObject
Tags
codeCoverageIgnore
Return values
static

createFromPath()

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

public static createFromPath(string $path[, non-empty-string $open_mode = 'r' ][, resource|null $context = null ]) : static

since version 9.27.0

Returns a new instance from a file path.

use League\Csv\AbstractCsv::from() instead

Parameters
$path : string
$open_mode : non-empty-string = 'r'
$context : resource|null = null

the resource context

Tags
codeCoverageIgnore
throws
UnavailableStream
Return values
static

createFromStream()

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

public static createFromStream(resource $stream) : static

since version 9.27.0

Returns a new instance from a PHP resource stream.

use League\Csv\AbstractCsv::from() instead

Parameters
$stream : resource
Tags
codeCoverageIgnore
Return values
static

createFromString()

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

public static createFromString([Stringable|string $content = '' ]) : static

since version 9.27.0

Returns a new instance from a string.

use League\Csv\AbstractCsv::fromString() instead

Parameters
$content : Stringable|string = ''
Tags
codeCoverageIgnore
Return values
static

download()

Outputs all data on the CSV file.

public download([string|null $filename = null ]) : int

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

Parameters
$filename : string|null = null
Tags
throws
InvalidArgumentException|Exception
Return values
int

each()

public each( Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64 Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 78 callable(array<string|int, mixed>, Array=): Array $callback) : bool
Parameters
$callback : Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64 Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 78 callable(array<string|int, mixed>, Array=): Array
Return values
bool

exists()

public exists( Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64 callable(array<string|int, mixed>, Array=): bool $callback) : bool
Parameters
$callback : Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64 callable(array<string|int, mixed>, Array=): bool
Return values
bool

fetchColumn()

Returns a single column from the next record of the tabular data.

public fetchColumn([string|int $index = 0 ]) : Iterator<int, mixed>

By default, if no value is supplied the first column is fetched

Parameters
$index : string|int = 0

CSV column index

Return values
Iterator<int, mixed>

fetchColumnByName()

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

public fetchColumnByName(string $name) : Iterator

since version 9.23.0

use League\Csv\Resultset::fetchColumn() instead

Parameters
$name : string
Tags
throws
Exception
codeCoverageIgnore
see
ResultSet::fetchColumn()
Return values
Iterator

fetchColumnByOffset()

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

public fetchColumnByOffset([int $offset = 0 ]) : Iterator

since version 9.23.0

use League\Csv\Resultset::fetchColumn() instead

Parameters
$offset : int = 0
Tags
throws
Exception
codeCoverageIgnore
see
ResultSet::fetchColumn()
Return values
Iterator

fetchOne()

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

public fetchOne([int $nth_record = 0 ]) : array<string|int, mixed>

since version 9.9.0

use League\Csv\Reader::nth() instead

Parameters
$nth_record : int = 0

the tabular data record offset

Tags
see
Reader::nth()
codeCoverageIgnore
Return values
array<string|int, mixed>

fetchPairs()

Returns the next key-value pairs from the tabular data (first column is the key, second column is the value).

public fetchPairs([string|int $offset_index = 0 ][, string|int $value_index = 1 ]) : Iterator

By default, if no column index is provided:

  • the first column is used to provide the keys
  • the second column is used to provide the value
Parameters
$offset_index : string|int = 0

The column index to serve as offset

$value_index : string|int = 1

The column index to serve as value

Return values
Iterator

filter()

public filter( Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64 Predicate|callable(array<string|int, mixed>, Array): bool $predicate) : TabularDataReader
Parameters
$predicate : Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64 Predicate|callable(array<string|int, mixed>, Array): bool
Tags
throws
Exception
throws
SyntaxError
Return values
TabularDataReader

first()

public first() : array<string|int, mixed>
Tags
throws
Exception
Return values
array<string|int, mixed>

firstAsObject()

public firstAsObject(class-string $className[, array<string|int, mixed> $header = [] ]) : object|null
Parameters
$className : class-string
$header : array<string|int, mixed> = []
Tags
throws
Exception
Return values
object|null

from()

Returns a new instance from a file path.

public static from(mixed $filename[, string $mode = 'r' ][, mixed $context = null ]) : static
Parameters
$filename : mixed

an SPL file object, a resource stream or a file path

$mode : string = 'r'

the file path open mode used with a file path or a SplFileInfo object

$context : mixed = null

the resource context used with a file pathor a SplFileInfo object

Return values
static

fromString()

Returns a new instance from a string.

public static fromString([Stringable|string $content = '' ]) : static
Parameters
$content : Stringable|string = ''
Return values
static

getContent()

Retrieves the CSV content.

public getContent() : string

since version 9.7.0

use League\Csv\AbstractCsv::toString() instead

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

Tags
see
AbstractCsv::toString
codeCoverageIgnore
Return values
string

getDelimiter()

Returns the current field delimiter.

public getDelimiter() : string
Return values
string

getEnclosure()

Returns the current field enclosure.

public getEnclosure() : string
Return values
string

getEscape()

Returns the current field escape character.

public getEscape() : string
Return values
string

getHeader()

Returns the header associated with the tabular data.

public getHeader() : array<string|int, string>
Tags
throws
SyntaxError

Returns the header record.

Return values
array<string|int, string>

getHeaderOffset()

Returns the header offset.

public getHeaderOffset() : int|null
Return values
int|null

getInputBOM()

Returns the BOM sequence of the given CSV.

public getInputBOM() : string
Return values
string

getIterator()

Returns the tabular data rows as an iterator object containing flat array.

public getIterator() : Iterator<string|int, TValue>
Tags
throws
Exception
Return values
Iterator<string|int, TValue>

getObjects()

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

public getObjects(class-string $className[, array<string|int, string> $header = [] ]) : Iterator

Since version 9.15.0

use League\Csv\Reader::getRecordsAsObject() instead

Parameters
$className : class-string
$header : array<string|int, string> = []
Tags
see
Reader::getRecordsAsObject()
codeCoverageIgnore
throws
Exception
throws
MappingFailed
throws
TypeCastingFailed
Return values
Iterator

getOutputBOM()

Returns the BOM sequence in use on Output methods.

public getOutputBOM() : string
Return values
string

getPathname()

Returns the pathname of the underlying document.

public getPathname() : string
Return values
string

getRecords()

Returns the tabular data records as an iterator object.

public getRecords([array<string|int, string> $header = [] ]) : Iterator<string|int, TValue>
Parameters
$header : array<string|int, string> = []
Tags
throws
Exception
Return values
Iterator<string|int, TValue>

getRecordsAsObject()

public getRecordsAsObject(T> $className[, array<string|int, string> $header = [] ]) : iterator<string|int, T>
Parameters
$className : T>
$header : array<string|int, string> = []
Tags
template
throws
Exception
throws
MappingFailed
throws
TypeCastingFailed
Return values
iterator<string|int, T>

getStreamFilterMode()

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

public getStreamFilterMode() : int

since version 9.7.0

use League\Csv\AbstractCsv::supportsStreamFilterOnRead() or League\Csv\AbstractCsv::supportsStreamFilterOnWrite() instead

Tags
see
AbstractCsv::supportsStreamFilterOnRead
see
AbstractCsv::supportsStreamFilterOnWrite
codeCoverageIgnore

Returns the stream filter mode.

Return values
int

hasStreamFilter()

Tells whether the specified stream filter is attached to the current stream.

public hasStreamFilter(string $filtername) : bool
Parameters
$filtername : string
Return values
bool

includeEmptyRecords()

Disables skipping empty records.

public includeEmptyRecords() : static
Return values
static

includeInputBOM()

Disables skipping Input BOM.

public includeInputBOM() : static
Return values
static

isEmptyRecordsIncluded()

Tells whether empty records are skipped by the instance.

public isEmptyRecordsIncluded() : bool
Return values
bool

isInputBOMIncluded()

Tells whether the BOM can be stripped if presents.

public isInputBOMIncluded() : bool
Return values
bool

jsonSerialize()

public jsonSerialize() : array<string|int, mixed>
Tags
throws
Exception
Return values
array<string|int, mixed>

last()

public last() : array<string|int, mixed>
Return values
array<string|int, mixed>

lastAsObject()

public lastAsObject(class-string $className[, array<string|int, mixed> $header = [] ]) : object|null
Parameters
$className : class-string
$header : array<string|int, mixed> = []
Tags
throws
ReflectionException
Return values
object|null

map()

Run a map over each container members.

public map(callable(array<string|int, mixed>, int): TMap $callback) : Iterator<string|int, TMap>
Parameters
$callback : callable(array<string|int, mixed>, int): TMap
Tags
template
Return values
Iterator<string|int, TMap>

matching()

EXPERIMENTAL WARNING! This method implementation will change in the next major point release.

public matching(string $expression) : iterable<int, TabularDataReader>

Extract all found fragment identifiers for the specifield tabular data

Parameters
$expression : string
Tags
experimental

since version 9.12.0

throws
SyntaxError
Return values
iterable<int, TabularDataReader>

matchingFirst()

EXPERIMENTAL WARNING! This method implementation will change in the next major point release.

public matchingFirst(string $expression) : TabularDataReader|null

Extract the first found fragment identifier of the tabular data or returns null

Parameters
$expression : string
Tags
experimental

since version 9.12.0

throws
SyntaxError
Return values
TabularDataReader|null

matchingFirstOrFail()

EXPERIMENTAL WARNING! This method implementation will change in the next major point release.

public matchingFirstOrFail(string $expression) : TabularDataReader

Extract the first found fragment identifier of the tabular data or fail

Parameters
$expression : string
Tags
experimental

since version 9.12.0

throws
SyntaxError
throws
FragmentNotFound
Return values
TabularDataReader

nth()

public nth(int $nth) : array<string|int, mixed>
Parameters
$nth : int
Tags
throws
Exception
Return values
array<string|int, mixed>

nthAsObject()

public nthAsObject(int $nth, class-string $className[, array<string|int, mixed> $header = [] ]) : object|null
Parameters
$nth : int
$className : class-string
$header : array<string|int, mixed> = []
Tags
throws
Exception
Return values
object|null

output()

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

public output([string|null $filename = null ]) : int

since version 9.18.0

use League\Csv\AbstractCsv::download() instead

Parameters
$filename : string|null = null
Tags
codeCoverageIgnore
see
AbstractCsv::download()

Outputs all data on the CSV file.

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

throws
Exception
Return values
int

prependStreamFilterOnRead()

Prepend a stream filter.

public prependStreamFilterOnRead(string $filtername[, mixed $params = null ]) : static
Parameters
$filtername : string
$params : mixed = null
Tags
throws
InvalidArgument

If the stream filter API can not be appended

throws
UnavailableFeature

If the stream filter API can not be used

Return values
static

prependStreamFilterOnWrite()

Prepend a stream filter.

public prependStreamFilterOnWrite(string $filtername[, mixed $params = null ]) : static
Parameters
$filtername : string
$params : mixed = null
Tags
throws
InvalidArgument

If the stream filter API can not be appended

throws
UnavailableFeature

If the stream filter API can not be used

Return values
static

reduce()

public reduce( Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64 Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64 callable(Array, array<string|int, mixed>, Array=): TInitial $callback[, TInitial|null $initial = null ]) : TInitial|null
Parameters
$callback : Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64 Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64 callable(Array, array<string|int, mixed>, Array=): TInitial
$initial : TInitial|null = null
Tags
template
Return values
TInitial|null

setDelimiter()

Sets the field delimiter.

public setDelimiter(string $delimiter) : static
Parameters
$delimiter : string
Tags
throws
InvalidArgument

If the Csv control character is not one character only.

Return values
static

setEnclosure()

Sets the field enclosure.

public setEnclosure(string $enclosure) : static
Parameters
$enclosure : string
Tags
throws
InvalidArgument

If the Csv control character is not one character only.

Return values
static

setEscape()

Sets the field escape character.

public setEscape(string $escape) : static
Parameters
$escape : string
Tags
throws
InvalidArgument

If the Csv control character is not one character only.

Return values
static

setHeaderOffset()

Selects the record to be used as the CSV header.

public setHeaderOffset(int|null $offset) : static

Because the header is represented as an array, to be valid a header MUST contain only unique string value.

Parameters
$offset : int|null

the header record offset

Tags
throws
Exception

if the offset is a negative integer

Return values
static

setOutputBOM()

Sets the BOM sequence to prepend the CSV on output.

public setOutputBOM(Bom|string|null $str) : static
Parameters
$str : Bom|string|null
Tags
throws
InvalidArgument

if the given non-empty string is not a valid BOM sequence

Return values
static

skipEmptyRecords()

Enables skipping empty records.

public skipEmptyRecords() : static
Return values
static

skipInputBOM()

Enables BOM Stripping.

public skipInputBOM() : static
Return values
static

supportsStreamFilter()

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

public supportsStreamFilter() : bool

since version 9.7.0

use League\Csv\AbstractCsv::supportsStreamFilterOnRead() or League\Csv\AbstractCsv::supportsStreamFilterOnWrite() instead

Tags
see
AbstractCsv::supportsStreamFilterOnRead
see
AbstractCsv::supportsStreamFilterOnWrite
codeCoverageIgnore

Tells whether the stream filter capabilities can be used.

Return values
bool

supportsStreamFilterOnRead()

Tells whether the stream filter read capabilities can be used.

public supportsStreamFilterOnRead() : bool
Return values
bool

supportsStreamFilterOnWrite()

Tells whether the stream filter write capabilities can be used.

public supportsStreamFilterOnWrite() : bool
Return values
bool

toString()

Retrieves the CSV content.

public toString() : string
Tags
throws
Exception

If the string representation cannot be returned

Return values
string

value()

public value([int|string $column = 0 ]) : mixed
Parameters
$column : int|string = 0

__construct()

protected __construct(SplFileObject|Stream $document) : mixed
Parameters
$document : SplFileObject|Stream
Tags
final

This method should not be overwritten in child classes

combineHeader()

protected combineHeader(Iterator $iterator, array<string|int, mixed> $header) : Iterator
Parameters
$iterator : Iterator
$header : array<string|int, mixed>
Return values
Iterator

computeHeader()

Returns the header to be used for iteration.

protected computeHeader(array<string|int, int|string> $header) : array<string|int, int|string>
Parameters
$header : array<string|int, int|string>
Tags
throws
SyntaxError

If the header contains non unique column name

Return values
array<string|int, int|string>

getDocument()

protected getDocument() : SplFileObject|Stream
Tags
throws
Exception

Returns the document as an Iterator.

Return values
SplFileObject|Stream

getLastRecord()

protected getLastRecord(array<string|int, mixed> $header) : array<string|int, mixed>
Parameters
$header : array<string|int, mixed>
Return values
array<string|int, mixed>

prepareHeader()

protected prepareHeader([array<string|int, string> $header = [] ]) : array<string|int, int|string>
Parameters
$header : array<string|int, string> = []
Tags
throws
SyntaxError
Return values
array<string|int, int|string>

prepareRecords()

protected prepareRecords() : Iterator
Tags
throws
Exception
Return values
Iterator

removeBOM()

Strips the BOM sequence from a record.

protected removeBOM(array<string|int, string> $record, int $bom_length, string $enclosure) : array<string|int, string>
Parameters
$record : array<string|int, string>
$bom_length : int
$enclosure : string
Return values
array<string|int, string>

resetProperties()

Reset dynamic object properties to improve performance.

protected resetProperties() : void

seekRow()

protected seekRow(int $offset) : array<string|int, mixed>
Parameters
$offset : int
Tags
throws
Exception

Returns the row at a given offset.

Return values
array<string|int, mixed>

sendHeaders()

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

protected sendHeaders(string $filename) : void

since version 9.17.0

the method no longer affect the outcome of the class, use League\Csv\HttpHeaders::forFileDownload instead

Parameters
$filename : string
Tags
throws
Exception

if the submitted header is invalid according to RFC 6266

see
HttpHeaders::forFileDownload()
see
https://tools.ietf.org/html/rfc6266#section-4.3
codeCoverageIgnore

Send the CSV headers.

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

setHeader()

Determines the CSV record header.

protected setHeader(int $offset) : array<string|int, string>
Parameters
$offset : int
Tags
throws
SyntaxError

If the header offset is set and no record is found or is the empty array

Return values
array<string|int, string>

stripBOM()

Strips the BOM sequence from the returned records if necessary.

protected stripBOM(Iterator $iterator, Bom|null $bom) : Iterator
Parameters
$iterator : Iterator
$bom : Bom|null
Return values
Iterator

        
On this page

Search results