From 837f7293ff6e50bce0e9ebbf4075d143adbb5cfc Mon Sep 17 00:00:00 2001 From: Ignace Nyamagana Butera Date: Fri, 14 Feb 2014 14:03:36 +0100 Subject: [PATCH] remove Bakame iterator2array implementation --- composer.json | 1 - src/Bakame/Csv/AbstractCsv.php | 4 +- src/Bakame/Csv/Iterator/functions.php | 60 --------------------------- src/Bakame/Csv/Reader.php | 6 +-- test/Bakame/Csv/CsvTest.php | 7 ---- 5 files changed, 5 insertions(+), 73 deletions(-) delete mode 100644 src/Bakame/Csv/Iterator/functions.php diff --git a/composer.json b/composer.json index 38e7c5dc..d84e9c2c 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,6 @@ "ext-mbstring" : "*" }, "autoload": { - "files": ["src/Bakame/Csv/Iterator/functions.php"], "psr-0": { "Bakame": ["src", "test"] } diff --git a/src/Bakame/Csv/AbstractCsv.php b/src/Bakame/Csv/AbstractCsv.php index 4c8e8a10..9b9bd715 100644 --- a/src/Bakame/Csv/AbstractCsv.php +++ b/src/Bakame/Csv/AbstractCsv.php @@ -403,7 +403,7 @@ public function jsonSerialize() if ('UTF-8' != $this->encoding) { $iterator = new MapIterator($iterator, function ($row) { foreach ($row as &$value) { - $value = mb_convert_encoding($value, 'UTF-8', $this->encoding); + $value = mb_convert_encoding($value, 'UTF-8', $this->encoding); } unset($value); @@ -411,6 +411,6 @@ public function jsonSerialize() }); } - return \Bakame\Csv\Iterator\iterator2Array($iterator, false); + return iterator_to_array($iterator, false); } } diff --git a/src/Bakame/Csv/Iterator/functions.php b/src/Bakame/Csv/Iterator/functions.php deleted file mode 100644 index 066b15af..00000000 --- a/src/Bakame/Csv/Iterator/functions.php +++ /dev/null @@ -1,60 +0,0 @@ - -* @copyright 2014 Ignace Nyamagana Butera -* @link https://github.com/nyamsprod/Bakame.csv -* @license http://opensource.org/licenses/MIT -* @version 4.2.0 -* @package Bakame.csv -* -* MIT LICENSE -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -namespace Bakame\Csv\Iterator; - -use Traversable; - -/** - * Faster iterator 2 array - * - * @param \Traversable $iterator - * @param boolean $use_keys should we use the Iterator keys - * - * @return array - */ -function iterator2Array(Traversable $iterator, $use_keys = true) -{ - $res = []; - if (! $use_keys) { - foreach ($iterator as $row) { - $res[] = $row; - } - - return $res; - } - foreach ($iterator as $key => $row) { - $res[$key] = $row; - } - - return $res; -} diff --git a/src/Bakame/Csv/Reader.php b/src/Bakame/Csv/Reader.php index 84394ffa..028a7bf6 100644 --- a/src/Bakame/Csv/Reader.php +++ b/src/Bakame/Csv/Reader.php @@ -129,7 +129,7 @@ public function fetchAll(callable $callable = null) { $iterator = $this->query($callable); - return \Bakame\Csv\Iterator\iterator2Array($iterator, false); + return iterator_to_array($iterator, false); } /** @@ -159,7 +159,7 @@ public function fetchAssoc(array $keys, callable $callable = null) return self::combineArray($keys, $row); }); - return \Bakame\Csv\Iterator\iterator2Array($iterator, false); + return iterator_to_array($iterator, false); } /** @@ -189,7 +189,7 @@ public function fetchCol($columnIndex, callable $callable = null) return $row[$columnIndex]; }); - return \Bakame\Csv\Iterator\iterator2Array($iterator, false); + return iterator_to_array($iterator, false); } /** diff --git a/test/Bakame/Csv/CsvTest.php b/test/Bakame/Csv/CsvTest.php index b2b017bd..e9125050 100644 --- a/test/Bakame/Csv/CsvTest.php +++ b/test/Bakame/Csv/CsvTest.php @@ -186,11 +186,4 @@ public static function getIso8859Csv() { return [[file_get_contents(__DIR__.'/data/prenoms.csv')]]; } - - public function testIterator2Array() - { - $res = \Bakame\Csv\Iterator\iterator2Array($this->csv); - $res2 = \Bakame\Csv\Iterator\iterator2Array($this->csv, false); - $this->assertSame($res, $res2); - } }