diff options
Diffstat (limited to 'src/Exporter')
-rw-r--r-- | src/Exporter/ColumnConsistencyValidator.php | 104 | ||||
-rw-r--r-- | src/Exporter/DataFormatterCollection.php | 85 | ||||
-rw-r--r-- | src/Exporter/DataValidatorCollection.php | 89 | ||||
-rw-r--r-- | src/Exporter/ForbiddenNullValuesValidator.php | 39 | ||||
-rw-r--r-- | src/Exporter/SkipNullValuesFormatter.php | 37 |
5 files changed, 0 insertions, 354 deletions
diff --git a/src/Exporter/ColumnConsistencyValidator.php b/src/Exporter/ColumnConsistencyValidator.php deleted file mode 100644 index 2afa574..0000000 --- a/src/Exporter/ColumnConsistencyValidator.php +++ /dev/null @@ -1,104 +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; - -use InvalidArgumentException; - -/** - * A class to manage column consistency on data insertion into a CSV - * - * @package League.csv - * @since 7.0.0 - * - */ -class ColumnConsistencyValidator -{ - /** - * The number of column per row - * - * @var int - */ - private $columns_count = -1; - - /** - * should the class detect the column count based the inserted row - * - * @var bool - */ - private $detect_columns_count = false; - - /** - * Set Inserted row column count - * - * @param int $value - * - * @throws \InvalidArgumentException If $value is lesser than -1 - * - * @return static - */ - public function setColumnsCount($value) - { - if (false === filter_var($value, FILTER_VALIDATE_INT, ['options' => ['min_range' => -1]])) { - throw new InvalidArgumentException('the column count must an integer greater or equals to -1'); - } - $this->detect_columns_count = false; - $this->columns_count = $value; - - return $this; - } - - /** - * Column count getter - * - * @return int - */ - public function getColumnsCount() - { - return $this->columns_count; - } - - /** - * The method will set the $columns_count property according to the next inserted row - * and therefore will also validate the next line whatever length it has no matter - * the current $columns_count property value. - * - * @return static - */ - public function autodetectColumnsCount() - { - $this->detect_columns_count = true; - - return $this; - } - - /** - * Is the submitted row valid - * - * @param array $row - * - * @return bool - */ - public function __invoke(array $row) - { - if ($this->detect_columns_count) { - $this->columns_count = count($row); - $this->detect_columns_count = false; - - return true; - } elseif (-1 == $this->columns_count) { - return true; - } - - return count($row) == $this->columns_count; - } -} 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/Exporter/DataValidatorCollection.php b/src/Exporter/DataValidatorCollection.php deleted file mode 100644 index 3a1dae5..0000000 --- a/src/Exporter/DataValidatorCollection.php +++ /dev/null @@ -1,89 +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; - -/** - * Trait to validate the row before insertion - * - * @package League.csv - * @since 7.0.0 - * - */ -trait DataValidatorCollection -{ - /** - * Callables to validate the row before insertion - * - * @var callable[] - */ - protected $validators = []; - - /** - * add a Validator to the collection - * - * @param callable $callable - * @param string $name the rule name - * - * @return $this - */ - public function addValidator(callable $callable, $name) - { - $name = trim($name); - $this->validators[$name] = $callable; - - return $this; - } - - /** - * Remove a validator from the collection - * - * @param string $name the validator name - * - * @return $this - */ - public function removeValidator($name) - { - $name = trim($name); - if (array_key_exists($name, $this->validators)) { - unset($this->validators[$name]); - } - - return $this; - } - - /** - * Detect if a validator is already registered - * - * @param string $name the validator name - * - * @return bool - */ - public function hasValidator($name) - { - $name = trim($name); - - return array_key_exists($name, $this->validators); - } - - /** - * Remove all registered validatior - * - * @return $this - */ - public function clearValidators() - { - $this->validators = []; - - return $this; - } -} diff --git a/src/Exporter/ForbiddenNullValuesValidator.php b/src/Exporter/ForbiddenNullValuesValidator.php deleted file mode 100644 index 383680d..0000000 --- a/src/Exporter/ForbiddenNullValuesValidator.php +++ /dev/null @@ -1,39 +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 class to validate null value handling on data insertion into a CSV - * - * @package League.csv - * @since 7.0.0 - * - */ -class ForbiddenNullValuesValidator -{ - /** - * Is the submitted row valid - * - * @param array $row - * - * @return bool - */ - public function __invoke(array $row) - { - $res = array_filter($row, function ($value) { - return is_null($value); - }); - - return count($res) == 0; - } -} diff --git a/src/Exporter/SkipNullValuesFormatter.php b/src/Exporter/SkipNullValuesFormatter.php deleted file mode 100644 index 62987a4..0000000 --- a/src/Exporter/SkipNullValuesFormatter.php +++ /dev/null @@ -1,37 +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 class to remove null value from data before insertion into a CSV - * - * @package League.csv - * @since 7.0.0 - * - */ -class SkipNullValuesFormatter -{ - /** - * remove null value form the submitted array - * - * @param array $row - * - * @return array - */ - public function __invoke(array $row) - { - return array_filter($row, function ($value) { - return ! is_null($value); - }); - } -} |