summaryrefslogtreecommitdiffstats
path: root/src/Modifier/QueryFilter.php
diff options
context:
space:
mode:
authorIgnace Nyamagana Butera <nyamsprod@gmail.com>2015-04-23 09:54:12 +0200
committerIgnace Nyamagana Butera <nyamsprod@gmail.com>2015-04-23 09:54:12 +0200
commitdd1a8a2d7fdf021cb2cab5ee1081e48b30f39b6b (patch)
tree5f7c9689fed66e9e2b05602023c620df479beca4 /src/Modifier/QueryFilter.php
parent6f8ba8efdc78d05326098603e870d45829881532 (diff)
downloadcsv-dd1a8a2d7fdf021cb2cab5ee1081e48b30f39b6b.zip
csv-dd1a8a2d7fdf021cb2cab5ee1081e48b30f39b6b.tar.gz
csv-dd1a8a2d7fdf021cb2cab5ee1081e48b30f39b6b.tar.bz2
improve QueryFilter internal code
Diffstat (limited to 'src/Modifier/QueryFilter.php')
-rw-r--r--src/Modifier/QueryFilter.php166
1 files changed, 83 insertions, 83 deletions
diff --git a/src/Modifier/QueryFilter.php b/src/Modifier/QueryFilter.php
index e181b2e..739028d 100644
--- a/src/Modifier/QueryFilter.php
+++ b/src/Modifier/QueryFilter.php
@@ -89,38 +89,6 @@ trait QueryFilter
}
/**
- * Remove the BOM sequence from the CSV
- *
- * @param Iterator $iterator
- *
- * @return Iterator
- */
- protected function applyBomStripping(Iterator $iterator)
- {
- if (! $this->isBomStrippable()) {
- $this->strip_bom = false;
- return $iterator;
- }
-
- $this->strip_bom = false;
- $bom = $this->getInputBom();
- return new MapIterator($iterator, function ($row, $index) use ($bom) {
- if (0 == $index) {
- $row[0] = mb_substr($row[0], mb_strlen($bom));
- }
-
- return $row;
- });
- }
-
- /**
- * Returns the BOM sequence of the given CSV
- *
- * @return string
- */
- abstract public function getInputBom();
-
- /**
* Set LimitIterator Offset
*
* @param $offset
@@ -155,27 +123,6 @@ trait QueryFilter
}
/**
- * Sort the Iterator
- *
- * @param \Iterator $iterator
- *
- * @return \LimitIterator
- */
- protected function applyIteratorInterval(Iterator $iterator)
- {
- if (0 == $this->iterator_offset && -1 == $this->iterator_limit) {
- return $iterator;
- }
- $offset = $this->iterator_offset;
- $limit = $this->iterator_limit;
-
- $this->iterator_limit = -1;
- $this->iterator_offset = 0;
-
- return new LimitIterator($iterator, $offset, $limit);
- }
-
- /**
* Set an Iterator sorting callable function
*
* @param callable $callable
@@ -231,36 +178,6 @@ trait QueryFilter
}
/**
- * Sort the Iterator
- *
- * @param \Iterator $iterator
- *
- * @return \ArrayIterator
- */
- protected function applyIteratorSortBy(Iterator $iterator)
- {
- if (! $this->iterator_sort_by) {
- return $iterator;
- }
- $nb_callbacks = count($this->iterator_sort_by);
- $this->iterator_sort_by = array_values($this->iterator_sort_by);
- $res = iterator_to_array($iterator, false);
- uasort($res, function ($rowA, $rowB) use ($nb_callbacks) {
- $res = 0;
- $index = 0;
- while ($index < $nb_callbacks && 0 === $res) {
- $res = $this->iterator_sort_by[$index]($rowA, $rowB);
- ++$index;
- }
-
- return $res;
- });
- $this->clearSortBy();
-
- return new ArrayIterator($res);
- }
-
- /**
* Set the Iterator filter method
*
* @param callable $callable
@@ -316,6 +233,38 @@ trait QueryFilter
}
/**
+ * Remove the BOM sequence from the CSV
+ *
+ * @param Iterator $iterator
+ *
+ * @return \Iterator
+ */
+ protected function applyBomStripping(Iterator $iterator)
+ {
+ if (! $this->isBomStrippable()) {
+ $this->strip_bom = false;
+ return $iterator;
+ }
+
+ $this->strip_bom = false;
+ $bom = $this->getInputBom();
+ return new MapIterator($iterator, function ($row, $index) use ($bom) {
+ if (0 == $index) {
+ $row[0] = mb_substr($row[0], mb_strlen($bom));
+ }
+
+ return $row;
+ });
+ }
+
+ /**
+ * Returns the BOM sequence of the given CSV
+ *
+ * @return string
+ */
+ abstract public function getInputBom();
+
+ /**
* Filter the Iterator
*
* @param \Iterator $iterator
@@ -331,4 +280,55 @@ trait QueryFilter
return $iterator;
}
+
+ /**
+ * Sort the Iterator
+ *
+ * @param \Iterator $iterator
+ *
+ * @return \Iterator
+ */
+ protected function applyIteratorInterval(Iterator $iterator)
+ {
+ if (0 == $this->iterator_offset && -1 == $this->iterator_limit) {
+ return $iterator;
+ }
+ $offset = $this->iterator_offset;
+ $limit = $this->iterator_limit;
+
+ $this->iterator_limit = -1;
+ $this->iterator_offset = 0;
+
+ return new LimitIterator($iterator, $offset, $limit);
+ }
+
+ /**
+ * Sort the Iterator
+ *
+ * @param \Iterator $iterator
+ *
+ * @return \Iterator
+ */
+ protected function applyIteratorSortBy(Iterator $iterator)
+ {
+ if (! $this->iterator_sort_by) {
+ return $iterator;
+ }
+ $nb_callbacks = count($this->iterator_sort_by);
+ $this->iterator_sort_by = array_values($this->iterator_sort_by);
+ $res = iterator_to_array($iterator, false);
+ uasort($res, function ($rowA, $rowB) use ($nb_callbacks) {
+ $res = 0;
+ $index = 0;
+ while ($index < $nb_callbacks && 0 === $res) {
+ $res = $this->iterator_sort_by[$index]($rowA, $rowB);
+ ++$index;
+ }
+
+ return $res;
+ });
+ $this->clearSortBy();
+
+ return new ArrayIterator($res);
+ }
}