Documentation

AbstractCsv
in package
implements ByteSequence

AbstractYes

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

$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.

$is_input_bom_included

protected bool $is_input_bom_included = false

$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

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

from()

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
throws
UnavailableStream
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

getInputBOM()

Returns the BOM sequence of the given CSV.

public getInputBOM() : string
Return values
string

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

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

includeInputBOM()

Disables skipping Input BOM.

public includeInputBOM() : static
Return values
static

isInputBOMIncluded()

Tells whether the BOM can be stripped if presents.

public isInputBOMIncluded() : bool
Return values
bool

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

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

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

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

__construct()

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

This method should not be overwritten in child classes

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
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


        
On this page

Search results