PHP 클래스 Coseva\CSV

상속: implements IteratorAggregat\IteratorAggregate
파일 보기 프로젝트 열기: johnnyfreeman/coseva 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_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

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