diff options
Diffstat (limited to 'src/Modifier/QueryFilter.php')
-rw-r--r-- | src/Modifier/QueryFilter.php | 98 |
1 files changed, 51 insertions, 47 deletions
diff --git a/src/Modifier/QueryFilter.php b/src/Modifier/QueryFilter.php index 50519b2..9435418 100644 --- a/src/Modifier/QueryFilter.php +++ b/src/Modifier/QueryFilter.php @@ -261,30 +261,6 @@ trait QueryFilter } /** - * Remove the BOM sequence from the CSV - * - * @param Iterator $iterator - * - * @return Iterator - */ - protected function applyBomStripping(Iterator $iterator) - { - if (!$this->strip_bom) { - return $iterator; - } - - if (!$this->isBomStrippable()) { - $this->strip_bom = false; - - return $iterator; - } - - $this->strip_bom = false; - - return $this->getStripBomIterator($iterator); - } - - /** * Return the Iterator without the BOM sequence * * @param Iterator $iterator @@ -328,9 +304,11 @@ trait QueryFilter $iterator = $this->applyBomStripping($iterator); $iterator = $this->applyIteratorFilter($iterator); $iterator = $this->applyIteratorSortBy($iterator); + $iterator = $this->applyIteratorInterval($iterator); + $this->returnType = AbstractCsv::TYPE_ARRAY; - return $this->applyIteratorInterval($iterator); + return $iterator; } /** @@ -339,6 +317,30 @@ trait QueryFilter abstract public function getIterator(); /** + * Remove the BOM sequence from the CSV + * + * @param Iterator $iterator + * + * @return Iterator + */ + protected function applyBomStripping(Iterator $iterator) + { + if (!$this->strip_bom) { + return $iterator; + } + + if (!$this->isBomStrippable()) { + $this->strip_bom = false; + + return $iterator; + } + + $this->strip_bom = false; + + return $this->getStripBomIterator($iterator); + } + + /** * Filter the Iterator * * @param Iterator $iterator @@ -362,17 +364,27 @@ trait QueryFilter * * @return Iterator */ - protected function applyIteratorInterval(Iterator $iterator) + protected function applyIteratorSortBy(Iterator $iterator) { - if (0 == $this->iterator_offset && -1 == $this->iterator_limit) { + if (!$this->iterator_sort_by) { return $iterator; } - $offset = $this->iterator_offset; - $limit = $this->iterator_limit; - $this->iterator_limit = -1; - $this->iterator_offset = 0; + $sortFunc = function ($rowA, $rowB) { + $sortRes = 0; + foreach ($this->iterator_sort_by as $callable) { + if (0 !== ($sortRes = call_user_func($callable, $rowA, $rowB))) { + break; + } + } - return new LimitIterator($iterator, $offset, $limit); + return $sortRes; + }; + + $obj = new ArrayObject(iterator_to_array($iterator)); + $obj->uasort($sortFunc); + $this->clearSortBy(); + + return $obj->getIterator(); } /** @@ -382,25 +394,17 @@ trait QueryFilter * * @return Iterator */ - protected function applyIteratorSortBy(Iterator $iterator) + protected function applyIteratorInterval(Iterator $iterator) { - if (!$this->iterator_sort_by) { + if (0 == $this->iterator_offset && -1 == $this->iterator_limit) { return $iterator; } - $obj = new ArrayObject(iterator_to_array($iterator, false)); - $obj->uasort(function ($rowA, $rowB) { - $sortRes = 0; - foreach ($this->iterator_sort_by as $callable) { - if (0 !== ($sortRes = call_user_func($callable, $rowA, $rowB))) { - break; - } - } - - return $sortRes; - }); - $this->clearSortBy(); + $offset = $this->iterator_offset; + $limit = $this->iterator_limit; + $this->iterator_limit = -1; + $this->iterator_offset = 0; - return $obj->getIterator(); + return new LimitIterator($iterator, $offset, $limit); } /** |