PHP Class Eccube\Service\CsvImportService

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Inheritance: implements Iterator, implements SeekableIterator, implements Countable
Datei anzeigen Open project: ec-cube/ec-cube Class Usage Examples

Protected Properties

Property Type Description
$columnHeaders array Column headers as read from the CSV file
$count integer Total number of rows in the CSV file
$duplicateHeadersFlag integer How to handle duplicate headers
$errors array Faulty CSV rows
$file SplFileObject CSV file
$headerRowNumber integer Number of the row that contains the column names
$headersCount integer In case of duplicate headers, this is always the number of unmerged headers.

Public Methods

Method Description
__construct ( SplFileObject $file, string $delimiter = ',', string $enclosure = '"', string $escape = '\' )
count ( )
current ( ) : array Return the current row as an array
getColumnHeaders ( ) : array Get column headers
getErrors ( ) : array Get rows that have an invalid number of columns
getFields ( )
getRow ( integer $number ) : array Get a row
hasErrors ( ) : boolean Does the reader contain any invalid rows?
key ( )
next ( )
rewind ( ) Rewind the file pointer
seek ( $pointer )
setColumnHeaders ( array $columnHeaders ) Set column headers
setHeaderRowNumber ( integer $rowNumber, integer $duplicates = null ) : boolean Set header row number
valid ( )

Protected Methods

Method Description
convertEncodingRows ( $row ) 行の文字エンコーディングを変換する.
incrementHeaders ( array $headers ) : array Add an increment to duplicate headers
mergeDuplicates ( array $line ) : array Merges values for duplicate headers into an array
readHeaderRow ( integer $rowNumber ) : array Read header row from CSV file

Method Details

__construct() public method

public __construct ( SplFileObject $file, string $delimiter = ',', string $enclosure = '"', string $escape = '\' )
$file SplFileObject
$delimiter string
$enclosure string
$escape string

convertEncodingRows() protected method

Windows 版 PHP7 環境では、ファイルエンコーディングが CP932 になるため UTF-8 に変換する. それ以外の環境では何もしない。
protected convertEncodingRows ( $row )

count() public method

public count ( )

current() public method

If a header row has been set, an associative array will be returned
public current ( ) : array
return array

getColumnHeaders() public method

Get column headers
public getColumnHeaders ( ) : array
return array

getErrors() public method

Get rows that have an invalid number of columns
public getErrors ( ) : array
return array

getFields() public method

public getFields ( )

getRow() public method

Get a row
public getRow ( integer $number ) : array
$number integer Row number
return array

hasErrors() public method

Does the reader contain any invalid rows?
public hasErrors ( ) : boolean
return boolean

incrementHeaders() protected method

So the following line: |duplicate|duplicate|duplicate| |first |second |third | Yields value: $duplicate => 'first', $duplicate1 => 'second', $duplicate2 => 'third'
protected incrementHeaders ( array $headers ) : array
$headers array
return array

key() public method

public key ( )

mergeDuplicates() protected method

So the following line: |duplicate|duplicate|duplicate| |first |second |third | Yields value: $duplicate => ['first', 'second', 'third']
protected mergeDuplicates ( array $line ) : array
$line array
return array

next() public method

public next ( )

readHeaderRow() protected method

Read header row from CSV file
protected readHeaderRow ( integer $rowNumber ) : array
$rowNumber integer Row number
return array

rewind() public method

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.
public rewind ( )

seek() public method

public seek ( $pointer )

setColumnHeaders() public method

Set column headers
public setColumnHeaders ( array $columnHeaders )
$columnHeaders array

setHeaderRowNumber() public method

Set header row number
public setHeaderRowNumber ( integer $rowNumber, integer $duplicates = null ) : boolean
$rowNumber integer Number of the row that contains column header names
$duplicates integer How to handle duplicates (optional). One of: - CsvReader::DUPLICATE_HEADERS_INCREMENT; increments duplicates (dup, dup1, dup2 etc.) - CsvReader::DUPLICATE_HEADERS_MERGE; merges values for duplicate headers into an array (dup => [value1, value2, value3])
return boolean

valid() public method

public valid ( )

Property Details

$columnHeaders protected_oe property

Column headers as read from the CSV file
protected array $columnHeaders
return array

$count protected_oe property

Total number of rows in the CSV file
protected int $count
return integer

$duplicateHeadersFlag protected_oe property

How to handle duplicate headers
protected int $duplicateHeadersFlag
return integer

$errors protected_oe property

Faulty CSV rows
protected array $errors
return array

$file protected_oe property

CSV file
protected SplFileObject $file
return SplFileObject

$headerRowNumber protected_oe property

Number of the row that contains the column names
protected int $headerRowNumber
return integer

$headersCount protected_oe property

In case of duplicate headers, this is always the number of unmerged headers.
protected int $headersCount
return integer