summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorignace nyamagana butera <nyamsprod@gmail.com>2015-11-27 09:33:46 +0100
committerignace nyamagana butera <nyamsprod@gmail.com>2015-11-27 10:26:09 +0100
commita94b152004b070cccf3a6cb669f247a6bd764bd6 (patch)
tree6388fbb85454fb1542666c94a5c45fcf37a03204 /src
parent0274c0fd79e0ba4ed98de3b0c4fc383aae014e63 (diff)
downloadcsv-a94b152004b070cccf3a6cb669f247a6bd764bd6.zip
csv-a94b152004b070cccf3a6cb669f247a6bd764bd6.tar.gz
csv-a94b152004b070cccf3a6cb669f247a6bd764bd6.tar.bz2
Improve returnType reset
Diffstat (limited to 'src')
-rw-r--r--src/AbstractCsv.php1
-rw-r--r--src/Reader.php7
2 files changed, 4 insertions, 4 deletions
diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php
index c13f52b..1e93c31 100644
--- a/src/AbstractCsv.php
+++ b/src/AbstractCsv.php
@@ -133,6 +133,7 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate
*/
public function getIterator()
{
+ $this->returnType = self::TYPE_ARRAY;
$iterator = $this->path;
if (!$iterator instanceof SplFileObject) {
$iterator = new SplFileObject($this->getStreamFilterPath(), $this->open_mode);
diff --git a/src/Reader.php b/src/Reader.php
index 140d959..f45b1bf 100644
--- a/src/Reader.php
+++ b/src/Reader.php
@@ -50,7 +50,6 @@ class Reader extends AbstractCsv
$iterator = $this->applyIteratorFilter($iterator);
$iterator = $this->applyIteratorSortBy($iterator);
$iterator = $this->applyIteratorInterval($iterator);
- $this->returnType = self::TYPE_ARRAY;
return $this->applyCallable($iterator, $callable);
}
@@ -147,6 +146,7 @@ class Reader extends AbstractCsv
*/
public function fetchColumn($columnIndex = 0, callable $callable = null)
{
+ $type = $this->returnType;
$columnIndex = $this->filterInteger($columnIndex, 0, 'the column index must be a positive integer or 0');
$filterColumn = function ($row) use ($columnIndex) {
@@ -158,7 +158,6 @@ class Reader extends AbstractCsv
};
$this->addFilter($filterColumn);
- $type = $this->returnType;
$iterator = $this->fetch($selectColumn);
$iterator = $this->applyCallable($iterator, $callable);
@@ -183,6 +182,7 @@ class Reader extends AbstractCsv
*/
public function fetchPairs($offsetColumnIndex = 0, $valueColumnIndex = 1, callable $callable = null)
{
+ $type = $this->returnType;
$offsetColumnIndex = $this->filterInteger($offsetColumnIndex, 0, 'the offset column index must be a positive integer or 0');
$valueColumnIndex = $this->filterInteger($valueColumnIndex, 0, 'the value column index must be a positive integer or 0');
$filterPairs = function ($row) use ($offsetColumnIndex, $valueColumnIndex) {
@@ -192,7 +192,6 @@ class Reader extends AbstractCsv
return [$row[$offsetColumnIndex], $row[$valueColumnIndex]];
};
$this->addFilter($filterPairs);
- $type = $this->returnType;
$iterator = $this->fetch($selectPairs);
$iterator = $this->applyCallable($iterator, $callable);
@@ -230,6 +229,7 @@ class Reader extends AbstractCsv
*/
public function fetchAssoc($offset_or_keys = 0, callable $callable = null)
{
+ $type = $this->returnType;
$keys = $this->getAssocKeys($offset_or_keys);
$keys_count = count($keys);
$combineArray = function (array $row) use ($keys, $keys_count) {
@@ -239,7 +239,6 @@ class Reader extends AbstractCsv
return array_combine($keys, $row);
};
- $type = $this->returnType;
$iterator = $this->fetch($combineArray);
$iterator = $this->applyCallable($iterator, $callable);