class CsvReader implements CountableReaderInterface, SeekableIterator

Class CsvReader

Constants

DUPLICATE_HEADERS_INCREMENT

DUPLICATE_HEADERS_MERGE

Properties

protected string $tmpFile File path of folder for temporary saving csv files
protected int $headerRowNumber Number of the row that contains the column names
protected SplFileObject $file CSV file
protected array $columnHeaders Column headers as read from the CSV file
protected int $headersCount Number of column headers, stored and re-used for performance
protected int $count Total number of rows in the CSV file
protected array $errors Faulty CSV rows
protected bool $strict Strict parsing - skip any lines mismatching header length
protected int $duplicateHeadersFlag How to handle duplicate headers

Methods

__construct(mixed $fileBase64, string $delimiter = ',', string $enclosure = '"', string $escape = '\\')

Construct CSV reader

array
current()

Return the current row as an array

array
getColumnHeaders()

Get column headers

setColumnHeaders(array $columnHeaders)

Set column headers

setHeaderRowNumber(mixed $rowNumber, null $duplicates = null)

No description

rewind()

Rewind the file pointer

count()

{@inheritdoc}

next()

{@inheritdoc}

valid()

{@inheritdoc}

key()

{@inheritdoc}

seek(int $pointer)

No description

array
getFields()

Get the field (column, property) names

array
getRow(int $number)

Get a row

array
getErrors()

Get rows that have an invalid number of columns

bool
hasErrors()

Does the reader contain any invalid rows?

bool
isStrict()

No description

$this
setStrict(mixed $strict)

No description

mixed
convert(CSVManagerInterface $manager, String $locale, array $csvHeaders = array(), array $propertyMappings = array())

No description

__destruct()

Destructor

array|string
readHeaderRow(int $rowNumber)

No description

array
incrementHeaders(array $headers)

No description

array
mergeDuplicates(array $line)

No description

Details

at line 102
__construct(mixed $fileBase64, string $delimiter = ',', string $enclosure = '"', string $escape = '\\')

Construct CSV reader

Parameters

mixed $fileBase64
string $delimiter Delimiter
string $enclosure Enclosure
string $escape Escape characters

at line 134
array current()

Return the current row as an array

If a header row has been set, an associative array will be returned

Return Value

array

at line 179
array getColumnHeaders()

Get column headers

Return Value

array

at line 191
CsvReader setColumnHeaders(array $columnHeaders)

Set column headers

Parameters

array $columnHeaders

Return Value

CsvReader

at line 207
CsvReader setHeaderRowNumber(mixed $rowNumber, null $duplicates = null)

Parameters

mixed $rowNumber
null $duplicates

Return Value

CsvReader

Exceptions

Exception

at line 223
rewind()

Rewind the file pointer

If a header row has been set, the pointer is set just below the header row. That way, when you iterate over the rows, that header row is skipped.

at line 234
count()

{@inheritdoc}

at line 250
next()

{@inheritdoc}

at line 258
valid()

{@inheritdoc}

at line 266
key()

{@inheritdoc}

at line 274
seek(int $pointer)

Parameters

int $pointer

at line 282
array getFields()

Get the field (column, property) names

Return Value

array

at line 294
array getRow(int $number)

Get a row

Parameters

int $number Row number

Return Value

array

at line 306
array getErrors()

Get rows that have an invalid number of columns

Return Value

array

at line 322
bool hasErrors()

Does the reader contain any invalid rows?

Return Value

bool

at line 330
bool isStrict()

Return Value

bool

at line 340
$this setStrict(mixed $strict)

Parameters

mixed $strict

Return Value

$this

at line 357
mixed convert(CSVManagerInterface $manager, String $locale, array $csvHeaders = array(), array $propertyMappings = array())

Parameters

CSVManagerInterface $manager
String $locale
array $csvHeaders
array $propertyMappings

Return Value

mixed

Exceptions

Exception

at line 383
__destruct()

Destructor

at line 395
protected array|string readHeaderRow(int $rowNumber)

Parameters

int $rowNumber

Return Value

array|string

Exceptions

Exception

at line 428
protected array incrementHeaders(array $headers)

Parameters

array $headers

Return Value

array

at line 450
protected array mergeDuplicates(array $line)

Parameters

array $line

Return Value

array