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
Afficher le fichier Open project: ec-cube/ec-cube Class Usage Examples

Protected Properties

Свойство 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.

Méthodes publiques

Méthode 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 ( )

Méthodes protégées

Méthode 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 méthode

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

convertEncodingRows() protected méthode

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

count() public méthode

public count ( )

current() public méthode

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

getColumnHeaders() public méthode

Get column headers
public getColumnHeaders ( ) : array
Résultat array

getErrors() public méthode

Get rows that have an invalid number of columns
public getErrors ( ) : array
Résultat array

getFields() public méthode

public getFields ( )

getRow() public méthode

Get a row
public getRow ( integer $number ) : array
$number integer Row number
Résultat array

hasErrors() public méthode

Does the reader contain any invalid rows?
public hasErrors ( ) : boolean
Résultat boolean

incrementHeaders() protected méthode

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
Résultat array

key() public méthode

public key ( )

mergeDuplicates() protected méthode

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

next() public méthode

public next ( )

readHeaderRow() protected méthode

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

rewind() public méthode

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 méthode

public seek ( $pointer )

setColumnHeaders() public méthode

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

setHeaderRowNumber() public méthode

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])
Résultat boolean

valid() public méthode

public valid ( )

Property Details

$columnHeaders protected_oe property

Column headers as read from the CSV file
protected array $columnHeaders
Résultat array

$count protected_oe property

Total number of rows in the CSV file
protected int $count
Résultat integer

$duplicateHeadersFlag protected_oe property

How to handle duplicate headers
protected int $duplicateHeadersFlag
Résultat integer

$errors protected_oe property

Faulty CSV rows
protected array $errors
Résultat array

$file protected_oe property

CSV file
protected SplFileObject $file
Résultat SplFileObject

$headerRowNumber protected_oe property

Number of the row that contains the column names
protected int $headerRowNumber
Résultat integer

$headersCount protected_oe property

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