diff options
author | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2015-02-10 09:47:47 +0100 |
---|---|---|
committer | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2015-02-10 09:47:47 +0100 |
commit | f4b09e18166c990879ef853c0f5aa44fe881ece3 (patch) | |
tree | 7c2c98afe87d68420df64e549851d5006a345a4b /src | |
parent | 6eafc3914df8ee3129cb1ef430351f8a9a3194c9 (diff) | |
download | csv-f4b09e18166c990879ef853c0f5aa44fe881ece3.zip csv-f4b09e18166c990879ef853c0f5aa44fe881ece3.tar.gz csv-f4b09e18166c990879ef853c0f5aa44fe881ece3.tar.bz2 |
improve SplFileObject flags handling
Diffstat (limited to 'src')
-rw-r--r-- | src/AbstractCsv.php | 5 | ||||
-rw-r--r-- | src/Config/Controls.php | 26 |
2 files changed, 5 insertions, 26 deletions
diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php index 8fb4339..3365a08 100644 --- a/src/AbstractCsv.php +++ b/src/AbstractCsv.php @@ -104,6 +104,7 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate $this->path = $this->normalizePath($path); $this->open_mode = strtolower($open_mode); + $this->flags = SplFileObject::READ_CSV|SplFileObject::DROP_NEW_LINE; $this->initStreamFilter($this->path); } @@ -171,11 +172,13 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate protected function newInstance($class_name, $open_mode) { $csv = new $class_name($this->path, $open_mode); - $csv->bom = $this->bom; $csv->delimiter = $this->delimiter; $csv->enclosure = $this->enclosure; $csv->escape = $this->escape; $csv->encodingFrom = $this->encodingFrom; + $csv->flags = $this->flags; + $csv->input_bom = $this->input_bom; + $csv->output_bom = $this->output_bom; $csv->newline = $this->newline; return $csv; diff --git a/src/Config/Controls.php b/src/Config/Controls.php index 5a9a0b3..952cb32 100644 --- a/src/Config/Controls.php +++ b/src/Config/Controls.php @@ -52,7 +52,7 @@ trait Controls * * @var int */ - protected $flags = SplFileObject::READ_CSV; + protected $flags; /** * newline character @@ -236,30 +236,6 @@ trait Controls return $this->flags; } - /** - * Returns the BOM sequence of the given CSV - * - * @return string - */ - public function getInputBOM() - { - $bom = [ - self::BOM_UTF8, - self::BOM_UTF16_BE, - self::BOM_UTF16_LE, - self::BOM_UTF32_BE, - self::BOM_UTF32_LE - ]; - $csv = $this->getIterator(); - $csv->rewind(); - $line = $csv->fgets(); - - $res = array_filter($bom, function ($sequence) use ($line) { - return strpos($line, $sequence) === 0; - }); - - return array_shift($res); - } /** * set the newline sequence characters |