CsvImportService
class CsvImportService implements Iterator, SeekableIterator, Countable
Copyright (C) 2012-2014 David de Boer david@ddeboer.nl
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.
Constants
DUPLICATE_HEADERS_INCREMENT |
|
DUPLICATE_HEADERS_MERGE |
|
Properties
protected integer | $headerRowNumber | Number of the row that contains the column names | |
protected SplFileObject | $file | CSV file | |
protected array | $columnHeaders | Column headers as read from the CSV file | |
protected integer | $headersCount | Number of column headers, stored and re-used for performance | |
protected integer | $count | Total number of rows in the CSV file | |
protected array | $errors | Faulty CSV rows | |
protected integer | $duplicateHeadersFlag | How to handle duplicate headers |
Methods
No description
Return the current row as an array
Get column headers
Set column headers
Set header row number
Rewind the file pointer
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
Get a row
Get rows that have an invalid number of columns
Does the reader contain any invalid rows?
Read header row from CSV file
Add an increment to duplicate headers
Merges values for duplicate headers into an array
行の文字エンコーディングを変換する.
Details
at line 114
__construct(SplFileObject $file, string $delimiter = ',', string $enclosure = '"', string $escape = '\\')
at line 139
array
current()
Return the current row as an array
If a header row has been set, an associative array will be returned
at line 175
array
getColumnHeaders()
Get column headers
at line 185
setColumnHeaders(array $columnHeaders)
Set column headers
at line 204
boolean
setHeaderRowNumber(integer $rowNumber, integer $duplicates = null)
Set header row number
at line 224
rewind()
Rewind the file pointer
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.
at line 235
count()
{@inheritdoc}
at line 251
next()
{@inheritdoc}
at line 259
valid()
{@inheritdoc}
at line 267
key()
{@inheritdoc}
at line 275
seek($pointer)
{@inheritdoc}
at line 283
getFields()
{@inheritdoc}
at line 295
array
getRow(integer $number)
Get a row
at line 307
array
getErrors()
Get rows that have an invalid number of columns
at line 323
boolean
hasErrors()
Does the reader contain any invalid rows?
at line 336
protected array
readHeaderRow(integer $rowNumber)
Read header row from CSV file
at line 358
protected array
incrementHeaders(array $headers)
Add an increment to duplicate headers
So the following line: |duplicate|duplicate|duplicate| |first |second |third |
Yields value: $duplicate => 'first', $duplicate1 => 'second', $duplicate2 => 'third'
at line 389
protected array
mergeDuplicates(array $line)
Merges values for duplicate headers into an array
So the following line: |duplicate|duplicate|duplicate| |first |second |third |
Yields value: $duplicate => ['first', 'second', 'third']
at line 413
protected
convertEncodingRows($row)
行の文字エンコーディングを変換する.
Windows 版 PHP7 環境では、ファイルエンコーディングが CP932 になるため UTF-8 に変換する. それ以外の環境では何もしない。