diff options
author | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2015-02-09 09:05:49 +0100 |
---|---|---|
committer | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2015-02-09 09:05:49 +0100 |
commit | 03ff1538d062013db1e8f221357ffc23f75814f0 (patch) | |
tree | 255eba03da941ab8cde9196dc3c442115c7c972a | |
parent | b3bf14ece7ed9ef1effb774579822949dd005276 (diff) | |
download | csv-03ff1538d062013db1e8f221357ffc23f75814f0.zip csv-03ff1538d062013db1e8f221357ffc23f75814f0.tar.gz csv-03ff1538d062013db1e8f221357ffc23f75814f0.tar.bz2 |
moving newline handling to controls traits
-rw-r--r-- | src/Config/Controls.php | 31 | ||||
-rw-r--r-- | src/Config/Factory.php | 9 | ||||
-rw-r--r-- | src/Writer.php | 42 |
3 files changed, 37 insertions, 45 deletions
diff --git a/src/Config/Controls.php b/src/Config/Controls.php index ba2aeee..5b807d7 100644 --- a/src/Config/Controls.php +++ b/src/Config/Controls.php @@ -55,6 +55,13 @@ trait Controls protected $flags = SplFileObject::READ_CSV; /** + * newline character + * + * @var string + */ + protected $newline = "\n"; + + /** * return a SplFileOjbect * * @return \SplFileOjbect @@ -256,4 +263,28 @@ trait Controls return array_shift($res); } + + /** + * set the newline sequence characters + * + * @param string $newline + * + * @return static + */ + public function setNewline($newline) + { + $this->newline = (string) $newline; + + return $this; + } + + /** + * return the current newline sequence characters + * + * @return string + */ + public function getNewline() + { + return $this->newline; + } } diff --git a/src/Config/Factory.php b/src/Config/Factory.php index 80eef38..c77ebc6 100644 --- a/src/Config/Factory.php +++ b/src/Config/Factory.php @@ -109,9 +109,12 @@ trait Factory ); } - $obj = new SplTempFileObject(); - $obj->fwrite(rtrim($str).$newline); + $file = new SplTempFileObject(); + $file->fwrite(rtrim($str).$newline); - return static::createFromFileObject($obj); + $obj = static::createFromFileObject($file); + $obj->setNewline($newline); + + return $obj; } } diff --git a/src/Writer.php b/src/Writer.php index 6a7067c..b3179e0 100644 --- a/src/Writer.php +++ b/src/Writer.php @@ -81,13 +81,6 @@ class Writer extends AbstractCsv protected $csv; /** - * newline character - * - * @var string - */ - protected $newline = "\n"; - - /** * should the class validate the input before insertion * * @var boolean @@ -129,30 +122,6 @@ class Writer extends AbstractCsv } /** - * set the newline sequence characters - * - * @param string $newline - * - * @return static - */ - public function setNewline($newline) - { - $this->newline = (string) $newline; - - return $this; - } - - /** - * return the current newline sequence characters - * - * @return string - */ - public function getNewline() - { - return $this->newline; - } - - /** * Set Inserted row column count * * @param int $value @@ -387,17 +356,6 @@ class Writer extends AbstractCsv } /** - * {@inheritdoc} - */ - public static function createFromString($str, $newline = PHP_EOL) - { - $obj = parent::createFromString($str, $newline); - $obj->setNewline($newline); - - return $obj; - } - - /** * The destructor */ public function __destruct() |