diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Config/Output.php | 6 | ||||
-rw-r--r-- | src/Modifier/QueryFilter.php | 16 | ||||
-rw-r--r-- | src/Reader.php | 10 |
3 files changed, 22 insertions, 10 deletions
diff --git a/src/Config/Output.php b/src/Config/Output.php index dd6e1ac..aeab560 100644 --- a/src/Config/Output.php +++ b/src/Config/Output.php @@ -129,11 +129,11 @@ trait Output { if (! $this->input_bom) { $bom = [ - self::BOM_UTF8, - self::BOM_UTF16_BE, - self::BOM_UTF16_LE, self::BOM_UTF32_BE, self::BOM_UTF32_LE, + self::BOM_UTF16_BE, + self::BOM_UTF16_LE, + self::BOM_UTF8, ]; $csv = $this->getIterator(); $csv->setFlags(SplFileObject::READ_CSV); diff --git a/src/Modifier/QueryFilter.php b/src/Modifier/QueryFilter.php index 03beb52..547f6f2 100644 --- a/src/Modifier/QueryFilter.php +++ b/src/Modifier/QueryFilter.php @@ -89,6 +89,11 @@ trait QueryFilter } /** + * {@inheritdoc} + */ + abstract public function getInputBom(); + + /** * Set LimitIterator Offset * * @param $offset @@ -255,6 +260,11 @@ trait QueryFilter return new MapIterator($iterator, function ($row, $index) use ($bom) { if (0 == $index) { $row[0] = mb_substr($row[0], mb_strlen($bom)); + $enclosure = $this->getEnclosure(); + //enclosure should be remove when a BOM sequence is stripped + if ($row[0][0] === $enclosure && mb_substr($row[0], -1, 1) == $enclosure) { + $row[0] = mb_substr($row[0], 1, -1); + } } return $row; @@ -262,11 +272,9 @@ trait QueryFilter } /** - * Returns the BOM sequence of the given CSV - * - * @return string + * {@inheritdoc} */ - abstract public function getInputBom(); + abstract public function getEnclosure(); /** * Filter the Iterator diff --git a/src/Reader.php b/src/Reader.php index 2955e11..2d5e213 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -17,6 +17,7 @@ use InvalidArgumentException; use Iterator; use League\Csv\Modifier; use LimitIterator; +use SplFileObject; /** * A class to manage extracting and filtering a CSV @@ -229,7 +230,10 @@ class Reader extends AbstractCsv */ protected function getRow($offset) { - $iterator = new LimitIterator($this->getIterator(), $offset, 1); + $csv = $this->getIterator(); + $csv->setFlags($this->getFlags() & ~SplFileObject::READ_CSV); + + $iterator = new LimitIterator($csv, $offset, 1); $iterator->rewind(); $res = $iterator->current(); if (empty($res)) { @@ -237,10 +241,10 @@ class Reader extends AbstractCsv } if (0 == $offset && $this->isBomStrippable()) { - $res[0] = mb_substr($res[0], mb_strlen($this->getInputBom())); + $res = mb_substr($res, mb_strlen($this->getInputBom())); } - return $res; + return str_getcsv($res, $this->delimiter, $this->enclosure, $this->escape); } /** |