abstract class Reader (View source)

Constants

MODE_COLUMN

SKIP_BLANK

SKIP_HEADER

STRICT

Properties

protected $separator
protected $separators
protected $stream

Methods

__construct(string $path)

Open file

__destruct()

No description

array<int, string>
getHeaders()

Get headers from file

resource
getStream()

Get file pointer resource

refresh()

Rewind the position of file pointer and refresh headers

setChunk(int|null $length)

Set maximum line length

setDataTransferObject(string|null $dto)

Set Data Transfer Object class

setEndOfLine(string $eol)

Set end-of-line

int
setFlags(int $flags)

Set the behavior of the fetch() method, and returns the previously defined flags.

callable
setFilter(callable $filter)

Set a custom filter that can be used to skip specific rows by returning false in the callback, or simply to modify the values received by reference.

setLimit(int $count, int $offset = 0)

Set the maximum number of rows returned and skips a certain number of rows before starting to return rows.

array<int, string>|array<string, string>|false
fetch()

Fetch a row from file pointer

converter()

Get a Converter instance.

Details

__construct(string $path)

Open file

Parameters

string $path

Exceptions

Exception

__destruct()

No description

array<int, string> getHeaders()

Get headers from file

Return Value

array<int, string>

resource getStream()

Get file pointer resource

Return Value

resource

refresh()

Rewind the position of file pointer and refresh headers

setChunk(int|null $length)

Set maximum line length

Parameters

int|null $length

Exceptions

Exception

setDataTransferObject(string|null $dto)

Set Data Transfer Object class

Note: To ensure the key format, use setFilter() method.

Parameters

string|null $dto

setEndOfLine(string $eol)

Set end-of-line

Parameters

string $eol

int setFlags(int $flags)

Set the behavior of the fetch() method, and returns the previously defined flags.

Parameters

int $flags

Return Value

int

Exceptions

Exception

callable setFilter(callable $filter)

Set a custom filter that can be used to skip specific rows by returning false in the callback, or simply to modify the values received by reference.

Note: For headers, the filter is only used to modify the values. Note: When defining a callback, the previous callback will be returned.

E.g:

$handle->setFilter(function (array &$fields, $index) {
  if ($index === 0) {
    // Convert header
    $fields = str_to_snake_case($fields);
  } else {
    // Convert rows
    $field = array_map('stripcslashes', $field);
  }
});

Parameters

callable $filter

Return Value

callable

Exceptions

Exception

setLimit(int $count, int $offset = 0)

Set the maximum number of rows returned and skips a certain number of rows before starting to return rows.

Note: If this method is not used, it will be limited to 1000 rows.

Parameters

int $count

Set limit rows (Note: Set 0 for unlimited).

int $offset

Set offset row.

array<int, string>|array<string, string>|false fetch()

Fetch a row from file pointer

Return Value

array<int, string>|array<string, string>|false

Exceptions

Exception

Converter converter()

Get a Converter instance.

Return Value

Converter