PHP Класс Coseva\CSV

Наследование: implements IteratorAggregat\IteratorAggregate
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_file SplFileObject Holds the CSV file pointer.
$_fileConfig array Holds config options for opening the file.
$_filters array Storage for filter callbacks to be executed during the parsing stage.
$_flushOnAfterFilter boolean Whether or not to flush empty rows after filtering.
$_garbageCollection boolean Whether or not to do garbage collection after parsing.
$_rows array Storage for parsed CSV rows.

Открытые методы

Метод Описание
__construct ( string $filename, string $open_mode = 'r', boolean $use_include_path = false ) : CSV Constructor for CSV.
__toString ( ) : string If you cast a CSV instance as a string it will print the contents on the CSV to an HTML table.
_applyFilters ( array $row ) : array Apply filters to the given row.
collectGarbage ( boolean $collect = true ) : CSV Whether or not to use garbage collection after parsing.
filter ( integer | callable $column, callable $callable = null ) : CSV Allows you to register any number of filters on a particular column or an entire row.
flushEmptyRows ( boolean $onAfterFilter = null ) : CSV Flush rows that have turned out empty, either after applying filters or rows that simply have been empty in the source CSV from the get-go.
flushFilters ( ) : CSV Flushes all active filters.
getInstance ( string $filename, $open_mode = 'r', $use_include_path = false ) : CSV Get an instance of CSV, based on the filename.
getIterator ( ) : ArrayIterator Get an array iterator for the CSV rows.
parse ( integer $rowOffset ) : CSV This method will convert the csv to an array and will run all registered filters against it.
setDelimiter ( string $delimiter ) : object Set a delimiter for the CSV file.
toJSON ( ) : string Use this to get the entire CSV in JSON format.
toTable ( ) : string This is a great way to display the filtered contents of the csv to you during the development process (for debugging purposes).

Приватные методы

Метод Описание
_flushEmptyRow ( mixed $row, mixed $index, boolean $trim = false ) : void Flush a row if it's empty.
_resolveFilename ( &$filename, boolean $use_include_path = false ) : boolean Resolve a given filename, keeping include paths in mind.

Описание методов

__construct() публичный Метод

To read a csv file, just pass the path to the .csv file.
См. также: http://php.net/manual/en/function.fopen.php for a list of modes
public __construct ( string $filename, string $open_mode = 'r', boolean $use_include_path = false ) : CSV
$filename string The file to read. Should be readable.
$open_mode string The mode in which to open the file
$use_include_path boolean Whether to search through include_path
Результат CSV $this

__toString() публичный Метод

If you cast a CSV instance as a string it will print the contents on the CSV to an HTML table.
public __toString ( ) : string
Результат string $this->toTable() HTML table of CSV contents

_applyFilters() публичный Метод

Apply filters to the given row.
public _applyFilters ( array $row ) : array
$row array
Результат array $row

collectGarbage() публичный Метод

Whether or not to use garbage collection after parsing.
public collectGarbage ( boolean $collect = true ) : CSV
$collect boolean
Результат CSV $this

filter() публичный Метод

Allows you to register any number of filters on a particular column or an entire row.
public filter ( integer | callable $column, callable $callable = null ) : CSV
$column integer | callable Specific column number or the callable to be applied. Optional: Zero-based column number. If this parameter is preset the $callable will recieve the contents of the current column (as a string), and will receive the entire (array based) row otherwise.
$callable callable Either the current row (as an array) or the current column (as a string) as the first parameter. The callable must return the new filtered row or column. Note: You can also use any native PHP functions that permit one parameter and return the new value, like trim, htmlspecialchars, urlencode, etc.
Результат CSV $this

flushEmptyRows() публичный Метод

Flush rows that have turned out empty, either after applying filters or rows that simply have been empty in the source CSV from the get-go.
public flushEmptyRows ( boolean $onAfterFilter = null ) : CSV
$onAfterFilter boolean whether or not to trigger while parsing. Leave this blank to trigger a flush right now.
Результат CSV $this

flushFilters() публичный Метод

Flushes all active filters.
public flushFilters ( ) : CSV
Результат CSV $this

getInstance() публичный статический Метод

Get an instance of CSV, based on the filename.
public static getInstance ( string $filename, $open_mode = 'r', $use_include_path = false ) : CSV
$filename string the CSV file to read. Should be readable. Filenames will be resolved. Symlinks will be followed.
Результат CSV self::$_instances[$key]

getIterator() публичный Метод

Required for implementing IteratorAggregate
public getIterator ( ) : ArrayIterator
Результат ArrayIterator

parse() публичный Метод

This method will convert the csv to an array and will run all registered filters against it.
public parse ( integer $rowOffset ) : CSV
$rowOffset integer Determines which row the parser will start on. Zero-based index. Note: When using a row offset, skipped rows will never be parsed nor stored. As such, we encourage to use different instances when mixing offsets, to prevent resultsets from interfering.
Результат CSV $this

setDelimiter() публичный Метод

Set a delimiter for the CSV file.
public setDelimiter ( string $delimiter ) : object
$delimiter string
Результат object $this CSV instance

toJSON() публичный Метод

Use this to get the entire CSV in JSON format.
public toJSON ( ) : string
Результат string JSON encoded string

toTable() публичный Метод

This is a great way to display the filtered contents of the csv to you during the development process (for debugging purposes).
public toTable ( ) : string
Результат string $output HTML table of CSV contents

Описание свойств

$_file защищенное свойство

Holds the CSV file pointer.
protected SplFileObject $_file
Результат SplFileObject

$_fileConfig защищенное свойство

Holds config options for opening the file.
protected array $_fileConfig
Результат array

$_filters защищенное свойство

Storage for filter callbacks to be executed during the parsing stage.
protected array $_filters
Результат array

$_flushOnAfterFilter защищенное свойство

Whether or not to flush empty rows after filtering.
protected bool $_flushOnAfterFilter
Результат boolean

$_garbageCollection защищенное свойство

Whether or not to do garbage collection after parsing.
protected bool $_garbageCollection
Результат boolean

$_rows защищенное свойство

Storage for parsed CSV rows.
protected array $_rows
Результат array