diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/AbstractCsv.php | 13 | ||||
-rw-r--r-- | src/Config/Controls.php | 11 | ||||
-rw-r--r-- | src/Config/Output.php | 4 | ||||
-rw-r--r-- | src/Iterators/MapIterator.php (renamed from src/Iterator/MapIterator.php) | 2 | ||||
-rw-r--r-- | src/Iterators/Query.php (renamed from src/Iterator/Query.php) | 2 | ||||
-rw-r--r-- | src/Reader.php | 11 | ||||
-rw-r--r-- | src/Writer.php | 40 |
7 files changed, 38 insertions, 45 deletions
diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php index db24a44..8fb4339 100644 --- a/src/AbstractCsv.php +++ b/src/AbstractCsv.php @@ -14,10 +14,7 @@ namespace League\Csv; use IteratorAggregate; use JsonSerializable; -use League\Csv\Config\Controls; -use League\Csv\Config\Factory; -use League\Csv\Config\Output; -use League\Csv\Config\StreamFilter; +use League\Csv\Config; use SplFileInfo; use SplFileObject; @@ -74,22 +71,22 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate /** * Csv Controls Trait */ - use Controls; + use Config\Controls; /** * Csv Factory Trait */ - use Factory; + use Config\Factory; /** * Csv Ouputting Trait */ - use Output; + use Config\Output; /** * Stream Filter API Trait */ - use StreamFilter; + use Config\StreamFilter; /** * Create a new instance diff --git a/src/Config/Controls.php b/src/Config/Controls.php index 5b807d7..5a9a0b3 100644 --- a/src/Config/Controls.php +++ b/src/Config/Controls.php @@ -77,7 +77,7 @@ trait Controls * * @return $this */ - public function setDelimiter($delimiter = ',') + public function setDelimiter($delimiter) { if (1 != mb_strlen($delimiter)) { throw new InvalidArgumentException('The delimiter must be a single character'); @@ -109,9 +109,7 @@ trait Controls { $iterator = $this->getIterator(); $iterator->setCsvControl($delimiter, $this->enclosure, $this->escape); - //"reduce" the csv length to a maximum of $nb_rows $iterator = new LimitIterator($iterator, 0, $nb_rows); - //return the parse rows $iterator = new CallbackFilterIterator($iterator, function ($row) { return is_array($row) && count($row) > 1; }); @@ -139,8 +137,7 @@ trait Controls $delimiters = array_filter($delimiters, function ($str) { return 1 == mb_strlen($str); }); - $delimiters = array_merge([$this->delimiter, ',', ';', "\t"], $delimiters); - $delimiters = array_unique($delimiters); + $delimiters = array_unique(array_merge([$this->delimiter, ',', ';', "\t"], $delimiters)); $res = array_fill_keys($delimiters, 0); array_walk($res, function (&$value, $delim) use ($nb_rows) { $value = $this->fetchRowsCountByDelimiter($delim, $nb_rows); @@ -160,7 +157,7 @@ trait Controls * * @return $this */ - public function setEnclosure($enclosure = '"') + public function setEnclosure($enclosure) { if (1 != mb_strlen($enclosure)) { throw new InvalidArgumentException('The enclosure must be a single character'); @@ -189,7 +186,7 @@ trait Controls * * @return $this */ - public function setEscape($escape = "\\") + public function setEscape($escape) { if (1 != mb_strlen($escape)) { throw new InvalidArgumentException('The escape character must be a single character'); diff --git a/src/Config/Output.php b/src/Config/Output.php index dcdd5f4..61d0c44 100644 --- a/src/Config/Output.php +++ b/src/Config/Output.php @@ -14,7 +14,7 @@ namespace League\Csv\Config; use DomDocument; use InvalidArgumentException; -use League\Csv\Iterator\MapIterator; +use League\Csv\Iterators\MapIterator; use Traversable; /** @@ -118,7 +118,7 @@ trait Output $filename = filter_var($filename, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: binary"); - header('Content-Disposition: attachment; filename="'.$filename); + header("Content-Disposition: attachment; filename=\"$filename\""); } //@codeCoverageIgnoreEnd $iterator = $this->getIterator(); diff --git a/src/Iterator/MapIterator.php b/src/Iterators/MapIterator.php index 5de3279..6cbdfe8 100644 --- a/src/Iterator/MapIterator.php +++ b/src/Iterators/MapIterator.php @@ -10,7 +10,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -namespace League\Csv\Iterator; +namespace League\Csv\Iterators; use IteratorIterator; use Traversable; diff --git a/src/Iterator/Query.php b/src/Iterators/Query.php index cb405cb..26d85de 100644 --- a/src/Iterator/Query.php +++ b/src/Iterators/Query.php @@ -10,7 +10,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -namespace League\Csv\Iterator; +namespace League\Csv\Iterators; use ArrayIterator; use CallbackFilterIterator; diff --git a/src/Reader.php b/src/Reader.php index 3986720..cab1176 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -15,8 +15,7 @@ namespace League\Csv; use CallbackFilterIterator; use InvalidArgumentException; use Iterator; -use League\Csv\Iterator\MapIterator; -use League\Csv\Iterator\Query; +use League\Csv\Iterators; use LimitIterator; /** @@ -31,7 +30,7 @@ class Reader extends AbstractCsv /** * Iterator Query Trait */ - use Query; + use Iterators\Query; /** * {@ihneritdoc} @@ -55,7 +54,7 @@ class Reader extends AbstractCsv $iterator = $this->applyIteratorSortBy($iterator); $iterator = $this->applyIteratorInterval($iterator); if (! is_null($callable)) { - $iterator = new MapIterator($iterator, $callable); + $iterator = new Iterators\MapIterator($iterator, $callable); } return $iterator; @@ -118,7 +117,7 @@ class Reader extends AbstractCsv } $iterator = $this->query($callable); - $iterator = new MapIterator($iterator, function ($row) use ($column_index) { + $iterator = new Iterators\MapIterator($iterator, function ($row) use ($column_index) { if (! array_key_exists($column_index, $row)) { return null; } @@ -181,7 +180,7 @@ class Reader extends AbstractCsv $keys = $this->getAssocKeys($offset_or_keys); $iterator = $this->query($callable); - $iterator = new MapIterator($iterator, function ($row) use ($keys) { + $iterator = new Iterators\MapIterator($iterator, function ($row) use ($keys) { return static::combineArray($keys, $row); }); diff --git a/src/Writer.php b/src/Writer.php index b3179e0..8e59952 100644 --- a/src/Writer.php +++ b/src/Writer.php @@ -30,22 +30,22 @@ class Writer extends AbstractCsv /** * set null handling mode to throw exception */ - const NULL_AS_EXCEPTION = 'NULL_AS_EXCEPTION'; + const NULL_AS_EXCEPTION = 1; /** * set null handling mode to remove cell */ - const NULL_AS_SKIP_CELL = 'NULL_AS_SKIP_CELL'; + const NULL_AS_SKIP_CELL = 2; /** * set null handling mode to convert null into empty string */ - const NULL_AS_EMPTY = 'NULL_AS_EMPTY'; + const NULL_AS_EMPTY = 3; /** * disable null handling */ - const NULL_HANDLING_DISABLED = 'NULL_HANDLING_DISABLED'; + const NULL_HANDLING_DISABLED = 4; /** * the object current null handling mode @@ -98,7 +98,7 @@ class Writer extends AbstractCsv */ public function setNullHandlingMode($value) { - if (!in_array($value, [ + if (! in_array($value, [ self::NULL_AS_SKIP_CELL, self::NULL_AS_EXCEPTION, self::NULL_AS_EMPTY, @@ -166,6 +166,20 @@ class Writer extends AbstractCsv } /** + * Tells wether the library should check or not the input + * + * @param bool $status + * + * @return static + */ + public function useValidation($status) + { + $this->useValidation = (bool) $status; + + return $this; + } + + /** * Add multiple lines to the CSV your are generating * * a simple helper/Wrapper method around insertOne @@ -192,20 +206,6 @@ class Writer extends AbstractCsv } /** - * Tells wether the library should check or not the input - * - * @param bool $status - * - * @return static - */ - public function useValidation($status) - { - $this->useValidation = (bool) $status; - - return $this; - } - - /** * Add a new CSV row to the generated CSV * * @param string[]|string $data a string, an array or an object implementing to '__toString' method @@ -268,7 +268,7 @@ class Writer extends AbstractCsv } if (! $this->isColumnsCountConsistent($row)) { - throw new RuntimeException('Adding '.count($row).' cells on a '.$this->columns_count.' cells per row CSV.'); + throw new RuntimeException('Adding '.count($row).' cells on a {$this->columns_count} cells per row CSV.'); } return $row; |