diff options
author | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2014-12-11 09:13:56 +0100 |
---|---|---|
committer | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2014-12-11 09:13:56 +0100 |
commit | ffc2e213fab7032262130140c0d57c559380f383 (patch) | |
tree | 3f88ba0026806957e1adb24ebc97d023452ec310 /src | |
parent | fbe42a2629bb378f4d9841df4bf3de4ca33def53 (diff) | |
download | csv-ffc2e213fab7032262130140c0d57c559380f383.zip csv-ffc2e213fab7032262130140c0d57c559380f383.tar.gz csv-ffc2e213fab7032262130140c0d57c559380f383.tar.bz2 |
improving added newline feature
Diffstat (limited to 'src')
-rw-r--r-- | src/AbstractCsv.php | 3 | ||||
-rw-r--r-- | src/Config/Controls.php | 33 | ||||
-rw-r--r-- | src/Writer.php | 47 |
3 files changed, 41 insertions, 42 deletions
diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php index 0986f18..8758caf 100644 --- a/src/AbstractCsv.php +++ b/src/AbstractCsv.php @@ -4,7 +4,7 @@ * * @license http://opensource.org/licenses/MIT * @link https://github.com/thephpleague/csv/ -* @version 6.1.0 +* @version 6.2.0 * @package League.csv * * For the full copyright and license information, please view the LICENSE @@ -218,7 +218,6 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate { $csv = new $class_name($this->path, $open_mode); $csv->delimiter = $this->delimiter; - $csv->lineEnding = $this->lineEnding; $csv->enclosure = $this->enclosure; $csv->escape = $this->escape; $csv->encodingFrom = $this->encodingFrom; diff --git a/src/Config/Controls.php b/src/Config/Controls.php index 7147d4d..e98058d 100644 --- a/src/Config/Controls.php +++ b/src/Config/Controls.php @@ -4,7 +4,7 @@ * * @license http://opensource.org/licenses/MIT * @link https://github.com/thephpleague/csv/ -* @version 6.1.0 +* @version 6.2.0 * @package League.csv * * For the full copyright and license information, please view the LICENSE @@ -34,13 +34,6 @@ trait Controls protected $delimiter = ','; /** - * the line ending - * - * @var string - */ - protected $lineEnding = "\n"; - - /** * the field enclosure character (one character only) * * @var string @@ -98,30 +91,6 @@ trait Controls } /** - * set the line ending - * - * @param string $lineEnding - * - * @return $this - */ - public function setLineEnding($lineEnding = "\n") - { - $this->lineEnding = $lineEnding; - - return $this; - } - - /** - * return the current line ending - * - * @return string - */ - public function getLineEnding() - { - return $this->lineEnding; - } - - /** * detect the actual number of row according to a delimiter * * @param string $delimiter a CSV delimiter diff --git a/src/Writer.php b/src/Writer.php index 9049bba..420ff6f 100644 --- a/src/Writer.php +++ b/src/Writer.php @@ -4,7 +4,7 @@ * * @license http://opensource.org/licenses/MIT * @link https://github.com/thephpleague/csv/ -* @version 6.1.0 +* @version 6.2.0 * @package League.csv * * For the full copyright and license information, please view the LICENSE @@ -76,6 +76,13 @@ class Writer extends AbstractCsv protected $csv; /** + * newline character + * + * @var string + */ + protected $newline = "\n"; + + /** * Tell the class how to handle null value * * @param int $value a Writer null behavior constant @@ -105,6 +112,30 @@ class Writer extends AbstractCsv } /** + * set the line ending + * + * @param string $newline + * + * @return $this + */ + public function setNewline($newline) + { + $this->newline = (string) $newline; + + return $this; + } + + /** + * return the current line ending + * + * @return string + */ + public function getNewline() + { + return $this->newline; + } + + /** * Set Inserted row column count * * @param int $value @@ -193,11 +224,12 @@ class Writer extends AbstractCsv that requires '.$this->columns_count.' columns per row.' ); } - $this->getCsv()->fputcsv($data, $this->delimiter, $this->enclosure); + $csv = $this->getCsv(); + $csv->fputcsv($data, $this->delimiter, $this->enclosure); - if ($this->lineEnding !== "\n") { - $this->getCsv()->fseek(-1, \SEEK_CUR); - $this->getCsv()->fwrite($this->lineEnding); + if ("\n" !== $this->newline) { + $csv->fseek(-1, SEEK_CUR); + $csv->fwrite($this->newline); } return $this; @@ -295,10 +327,9 @@ class Writer extends AbstractCsv */ protected function getCsv() { - if (! is_null($this->csv)) { - return $this->csv; + if (is_null($this->csv)) { + $this->csv = $this->getIterator(); } - $this->csv = $this->getIterator(); return $this->csv; } |