summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/AbstractCsv.php3
-rw-r--r--src/Config/Output.php4
-rw-r--r--src/Exporter/DataFormatterCollection.php85
-rw-r--r--src/Modifier/MapIterator.php (renamed from src/Iterators/MapIterator.php)2
-rw-r--r--src/Modifier/QueryFilter.php (renamed from src/Iterators/Query.php)4
-rw-r--r--src/Modifier/RowFilter.php (renamed from src/Exporter/DataValidatorCollection.php)68
-rw-r--r--src/Modifier/StreamFilter.php (renamed from src/Config/StreamFilter.php)2
-rw-r--r--src/Plugin/ColumnConsistencyValidator.php (renamed from src/Exporter/ColumnConsistencyValidator.php)10
-rw-r--r--src/Plugin/ForbiddenNullValuesValidator.php (renamed from src/Exporter/ForbiddenNullValuesValidator.php)4
-rw-r--r--src/Plugin/SkipNullValuesFormatter.php (renamed from src/Exporter/SkipNullValuesFormatter.php)2
-rw-r--r--src/Reader.php10
-rw-r--r--src/Writer.php11
12 files changed, 87 insertions, 118 deletions
diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php
index b23b74f..ee9b839 100644
--- a/src/AbstractCsv.php
+++ b/src/AbstractCsv.php
@@ -16,6 +16,7 @@ use InvalidArgumentException;
use IteratorAggregate;
use JsonSerializable;
use League\Csv\Config;
+use League\Csv\Modifier;
use SplFileInfo;
use SplFileObject;
use SplTempFileObject;
@@ -83,7 +84,7 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate
/**
* Stream Filter API Trait
*/
- use Config\StreamFilter;
+ use Modifier\StreamFilter;
/**
* Create a new instance
diff --git a/src/Config/Output.php b/src/Config/Output.php
index f6af901..8b9f178 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\Iterators\MapIterator;
+use League\Csv\Modifier;
use SplFileObject;
use Traversable;
@@ -229,7 +229,7 @@ trait Output
return $iterator;
}
- return new MapIterator($iterator, function ($row) {
+ return new Modifier\MapIterator($iterator, function ($row) {
foreach ($row as &$value) {
$value = mb_convert_encoding($value, 'UTF-8', $this->encodingFrom);
}
diff --git a/src/Exporter/DataFormatterCollection.php b/src/Exporter/DataFormatterCollection.php
deleted file mode 100644
index 495c5e3..0000000
--- a/src/Exporter/DataFormatterCollection.php
+++ /dev/null
@@ -1,85 +0,0 @@
-<?php
-/**
-* This file is part of the League.csv library
-*
-* @license http://opensource.org/licenses/MIT
-* @link https://github.com/thephpleague/csv/
-* @version 7.0.0
-* @package League.csv
-*
-* For the full copyright and license information, please view the LICENSE
-* file that was distributed with this source code.
-*/
-namespace League\Csv\Exporter;
-
-/**
- * A trait to format the row before insertion
- *
- * @package League.csv
- * @since 7.0.0
- *
- */
-trait DataFormatterCollection
-{
- /**
- * Callables to format the row before insertion
- *
- * @var callable[]
- */
- protected $formatters = [];
-
- /**
- * add a formatter to the collection
- *
- * @param callable $callable
- *
- * @return $this
- */
- public function addFormatter(callable $callable)
- {
- $this->formatters[] = $callable;
-
- return $this;
- }
-
- /**
- * Remove a formatter from the collection
- *
- * @param callable $callable
- *
- * @return $this
- */
- public function removeFormatter(callable $callable)
- {
- $res = array_search($callable, $this->formatters, true);
- if (false !== $res) {
- unset($this->formatters[$res]);
- }
-
- return $this;
- }
-
- /**
- * Detect if the formatter is already registered
- *
- * @param callable $callable
- *
- * @return bool
- */
- public function hasFormatter(callable $callable)
- {
- return false !== array_search($callable, $this->formatters, true);
- }
-
- /**
- * Remove all registered formatter
- *
- * @return $this
- */
- public function clearFormatters()
- {
- $this->formatters = [];
-
- return $this;
- }
-}
diff --git a/src/Iterators/MapIterator.php b/src/Modifier/MapIterator.php
index 9f91448..7360f42 100644
--- a/src/Iterators/MapIterator.php
+++ b/src/Modifier/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\Iterators;
+namespace League\Csv\Modifier;
use IteratorIterator;
use Traversable;
diff --git a/src/Iterators/Query.php b/src/Modifier/QueryFilter.php
index 90480f8..229ea42 100644
--- a/src/Iterators/Query.php
+++ b/src/Modifier/QueryFilter.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\Iterators;
+namespace League\Csv\Modifier;
use ArrayIterator;
use CallbackFilterIterator;
@@ -25,7 +25,7 @@ use LimitIterator;
* @since 4.2.1
*
*/
-trait Query
+trait QueryFilter
{
/**
* Callables to filter the iterator
diff --git a/src/Exporter/DataValidatorCollection.php b/src/Modifier/RowFilter.php
index 3a1dae5..b0aec16 100644
--- a/src/Exporter/DataValidatorCollection.php
+++ b/src/Modifier/RowFilter.php
@@ -10,16 +10,16 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace League\Csv\Exporter;
+namespace League\Csv\Modifier;
/**
- * Trait to validate the row before insertion
+ * Trait to format and validate the row before insertion
*
* @package League.csv
* @since 7.0.0
*
*/
-trait DataValidatorCollection
+trait RowFilter
{
/**
* Callables to validate the row before insertion
@@ -29,6 +29,68 @@ trait DataValidatorCollection
protected $validators = [];
/**
+ * Callables to format the row before insertion
+ *
+ * @var callable[]
+ */
+ protected $formatters = [];
+
+ /**
+ * add a formatter to the collection
+ *
+ * @param callable $callable
+ *
+ * @return $this
+ */
+ public function addFormatter(callable $callable)
+ {
+ $this->formatters[] = $callable;
+
+ return $this;
+ }
+
+ /**
+ * Remove a formatter from the collection
+ *
+ * @param callable $callable
+ *
+ * @return $this
+ */
+ public function removeFormatter(callable $callable)
+ {
+ $res = array_search($callable, $this->formatters, true);
+ if (false !== $res) {
+ unset($this->formatters[$res]);
+ }
+
+ return $this;
+ }
+
+ /**
+ * Detect if the formatter is already registered
+ *
+ * @param callable $callable
+ *
+ * @return bool
+ */
+ public function hasFormatter(callable $callable)
+ {
+ return false !== array_search($callable, $this->formatters, true);
+ }
+
+ /**
+ * Remove all registered formatter
+ *
+ * @return $this
+ */
+ public function clearFormatters()
+ {
+ $this->formatters = [];
+
+ return $this;
+ }
+
+ /**
* add a Validator to the collection
*
* @param callable $callable
diff --git a/src/Config/StreamFilter.php b/src/Modifier/StreamFilter.php
index cf2aa8f..1bbdff5 100644
--- a/src/Config/StreamFilter.php
+++ b/src/Modifier/StreamFilter.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\Config;
+namespace League\Csv\Modifier;
use LogicException;
use OutOfBoundsException;
diff --git a/src/Exporter/ColumnConsistencyValidator.php b/src/Plugin/ColumnConsistencyValidator.php
index 2afa574..191a28b 100644
--- a/src/Exporter/ColumnConsistencyValidator.php
+++ b/src/Plugin/ColumnConsistencyValidator.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\Exporter;
+namespace League\Csv\Plugin;
use InvalidArgumentException;
@@ -44,7 +44,7 @@ class ColumnConsistencyValidator
*
* @throws \InvalidArgumentException If $value is lesser than -1
*
- * @return static
+ * @return void
*/
public function setColumnsCount($value)
{
@@ -53,8 +53,6 @@ class ColumnConsistencyValidator
}
$this->detect_columns_count = false;
$this->columns_count = $value;
-
- return $this;
}
/**
@@ -72,13 +70,11 @@ class ColumnConsistencyValidator
* and therefore will also validate the next line whatever length it has no matter
* the current $columns_count property value.
*
- * @return static
+ * @return void
*/
public function autodetectColumnsCount()
{
$this->detect_columns_count = true;
-
- return $this;
}
/**
diff --git a/src/Exporter/ForbiddenNullValuesValidator.php b/src/Plugin/ForbiddenNullValuesValidator.php
index 383680d..5c4ff47 100644
--- a/src/Exporter/ForbiddenNullValuesValidator.php
+++ b/src/Plugin/ForbiddenNullValuesValidator.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\Exporter;
+namespace League\Csv\Plugin;
/**
* A class to validate null value handling on data insertion into a CSV
@@ -34,6 +34,6 @@ class ForbiddenNullValuesValidator
return is_null($value);
});
- return count($res) == 0;
+ return ! $res;
}
}
diff --git a/src/Exporter/SkipNullValuesFormatter.php b/src/Plugin/SkipNullValuesFormatter.php
index 62987a4..55addce 100644
--- a/src/Exporter/SkipNullValuesFormatter.php
+++ b/src/Plugin/SkipNullValuesFormatter.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\Exporter;
+namespace League\Csv\Plugin;
/**
* A class to remove null value from data before insertion into a CSV
diff --git a/src/Reader.php b/src/Reader.php
index ddb88f7..eb78dc3 100644
--- a/src/Reader.php
+++ b/src/Reader.php
@@ -15,7 +15,7 @@ namespace League\Csv;
use CallbackFilterIterator;
use InvalidArgumentException;
use Iterator;
-use League\Csv\Iterators;
+use League\Csv\Modifier;
use LimitIterator;
/**
@@ -30,7 +30,7 @@ class Reader extends AbstractCsv
/**
* Iterator Query Trait
*/
- use Iterators\Query;
+ use Modifier\QueryFilter;
/**
* {@ihneritdoc}
@@ -54,7 +54,7 @@ class Reader extends AbstractCsv
$iterator = $this->applyIteratorSortBy($iterator);
$iterator = $this->applyIteratorInterval($iterator);
if (! is_null($callable)) {
- $iterator = new Iterators\MapIterator($iterator, $callable);
+ $iterator = new Modifier\MapIterator($iterator, $callable);
}
return $iterator;
@@ -120,7 +120,7 @@ class Reader extends AbstractCsv
$iterator = new CallbackFilterIterator($iterator, function ($row) use ($column_index) {
return array_key_exists($column_index, $row);
});
- $iterator = new Iterators\MapIterator($iterator, function ($row) use ($column_index) {
+ $iterator = new Modifier\MapIterator($iterator, function ($row) use ($column_index) {
return $row[$column_index];
});
@@ -179,7 +179,7 @@ class Reader extends AbstractCsv
$keys = $this->getAssocKeys($offset_or_keys);
$iterator = $this->query($callable);
- $iterator = new Iterators\MapIterator($iterator, function ($row) use ($keys) {
+ $iterator = new Modifier\MapIterator($iterator, function ($row) use ($keys) {
return static::combineArray($keys, $row);
});
diff --git a/src/Writer.php b/src/Writer.php
index cd64d5c..306ba66 100644
--- a/src/Writer.php
+++ b/src/Writer.php
@@ -14,7 +14,7 @@ namespace League\Csv;
use InvalidArgumentException;
use League\Csv\Exception\InvalidRowException;
-use League\Csv\Exporter;
+use League\Csv\Modifier;
use Traversable;
/**
@@ -39,14 +39,9 @@ class Writer extends AbstractCsv
protected $csv;
/**
- * Data Formatters Collection trait
+ * Data Formatters/Validators trait
*/
- use Exporter\DataFormatterCollection;
-
- /**
- * Data Validators Collection trait
- */
- use Exporter\DataValidatorCollection;
+ use Modifier\RowFilter;
/**
* Add multiple lines to the CSV your are generating