AbstractCsv
in package
implements
ByteSequence
An abstract class to enable CSV document loading.
Table of Contents
Interfaces
- ByteSequence
- Defines constants for common BOM sequences.
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>>
- $input_bom : Bom|null
- $is_input_bom_included : bool
- $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.
- 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.
- 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.
- getInputBOM() : string
- Returns the BOM sequence of the given CSV.
- getOutputBOM() : string
- Returns the BOM sequence in use on Output methods.
- getPathname() : string
- Returns the pathname of the underlying document.
- 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.
- includeInputBOM() : static
- Disables skipping Input BOM.
- isInputBOMIncluded() : bool
- Tells whether the BOM can be stripped if presents.
- 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.
- setDelimiter() : static
- Sets the field delimiter.
- setEnclosure() : static
- Sets the field enclosure.
- setEscape() : static
- Sets the field escape character.
- setOutputBOM() : static
- Sets the BOM sequence to prepend the CSV on output.
- skipInputBOM() : static
- Enables BOM Stripping.
- 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.
- __construct() : mixed
- resetProperties() : void
- Reset dynamic object properties to improve performance.
- sendHeaders() : void
- DEPRECATION WARNING! This method will be removed in the next major point release.
Constants
STREAM_FILTER_MODE
protected
mixed
STREAM_FILTER_MODE
= \STREAM_FILTER_READ
Properties
$delimiter
protected
string
$delimiter
= ','
$document read-only
protected
SplFileObject|Stream
$document
$enclosure
protected
string
$enclosure
= '"'
$escape
protected
string
$escape
= '\\'
$formatters
protected
array<string|int, callable(array<string|int, mixed>): array<string|int, mixed>>
$formatters
= []
collection of Closure to format the record before reading.
$input_bom
protected
Bom|null
$input_bom
= null
$is_input_bom_included
protected
bool
$is_input_bom_included
= false
$output_bom
protected
Bom|null
$output_bom
= null
$stream_filters
protected
array<string, bool>
$stream_filters
= []
collection of stream filters.
Methods
__clone()
public
__clone() : mixed
Tags
__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
Return values
stringaddFormatter()
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
staticaddStreamFilter()
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
Return values
staticappendStreamFilterOnRead()
Append a stream filter.
public
appendStreamFilterOnRead(string $filtername[, mixed $params = null ]) : static
Parameters
- $filtername : string
- $params : mixed = null
Tags
Return values
staticappendStreamFilterOnWrite()
Append a stream filter.
public
appendStreamFilterOnWrite(string $filtername[, mixed $params = null ]) : static
Parameters
- $filtername : string
- $params : mixed = null
Tags
Return values
staticchunk()
Returns the CSV document as a Generator of string chunk.
public
chunk(int $length) : Generator
Parameters
- $length : int
Tags
Return values
GeneratorcreateFromFileObject()
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
Return values
staticcreateFromPath()
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
Return values
staticcreateFromStream()
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
Return values
staticcreateFromString()
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
Return values
staticdownload()
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
Return values
intfrom()
Returns a new instance from a file path.
public
static from(SplFileInfo|SplFileObject|resource|string $filename[, non-empty-string $mode = 'r+' ][, resource|null $context = null ]) : static
Parameters
- $filename : SplFileInfo|SplFileObject|resource|string
-
an SPL file object, a resource stream or a file path
- $mode : non-empty-string = 'r+'
-
the file path open mode used with a file path or a SplFileInfo object
- $context : resource|null = null
-
the resource context used with a file pathor a SplFileInfo object
Tags
Return values
staticfromString()
Returns a new instance from a string.
public
static fromString([Stringable|string $content = '' ]) : static
Parameters
- $content : Stringable|string = ''
Return values
staticgetContent()
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
Return values
stringgetDelimiter()
Returns the current field delimiter.
public
getDelimiter() : string
Return values
stringgetEnclosure()
Returns the current field enclosure.
public
getEnclosure() : string
Return values
stringgetEscape()
Returns the current field escape character.
public
getEscape() : string
Return values
stringgetInputBOM()
Returns the BOM sequence of the given CSV.
public
getInputBOM() : string
Return values
stringgetOutputBOM()
Returns the BOM sequence in use on Output methods.
public
getOutputBOM() : string
Return values
stringgetPathname()
Returns the pathname of the underlying document.
public
getPathname() : string
Return values
stringgetStreamFilterMode()
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
Return values
inthasStreamFilter()
Tells whether the specified stream filter is attached to the current stream.
public
hasStreamFilter(string $filtername) : bool
Parameters
- $filtername : string
Return values
boolincludeInputBOM()
Disables skipping Input BOM.
public
includeInputBOM() : static
Return values
staticisInputBOMIncluded()
Tells whether the BOM can be stripped if presents.
public
isInputBOMIncluded() : bool
Return values
booloutput()
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
Return values
intprependStreamFilterOnRead()
Prepend a stream filter.
public
prependStreamFilterOnRead(string $filtername[, mixed $params = null ]) : static
Parameters
- $filtername : string
- $params : mixed = null
Tags
Return values
staticprependStreamFilterOnWrite()
Prepend a stream filter.
public
prependStreamFilterOnWrite(string $filtername[, mixed $params = null ]) : static
Parameters
- $filtername : string
- $params : mixed = null
Tags
Return values
staticsetDelimiter()
Sets the field delimiter.
public
setDelimiter(string $delimiter) : static
Parameters
- $delimiter : string
Tags
Return values
staticsetEnclosure()
Sets the field enclosure.
public
setEnclosure(string $enclosure) : static
Parameters
- $enclosure : string
Tags
Return values
staticsetEscape()
Sets the field escape character.
public
setEscape(string $escape) : static
Parameters
- $escape : string
Tags
Return values
staticsetOutputBOM()
Sets the BOM sequence to prepend the CSV on output.
public
setOutputBOM(Bom|string|null $str) : static
Parameters
- $str : Bom|string|null
Tags
Return values
staticskipInputBOM()
Enables BOM Stripping.
public
skipInputBOM() : static
Return values
staticsupportsStreamFilter()
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
Return values
boolsupportsStreamFilterOnRead()
Tells whether the stream filter read capabilities can be used.
public
supportsStreamFilterOnRead() : bool
Return values
boolsupportsStreamFilterOnWrite()
Tells whether the stream filter write capabilities can be used.
public
supportsStreamFilterOnWrite() : bool
Return values
booltoString()
Retrieves the CSV content.
public
toString() : string
Tags
Return values
string__construct()
protected
__construct(SplFileObject|Stream $document) : mixed
Parameters
- $document : SplFileObject|Stream
Tags
resetProperties()
Reset dynamic object properties to improve performance.
protected
resetProperties() : void
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