@@ -168,45 +168,6 @@ public function addSortBy(callable $callable)
168168 return $ this ;
169169 }
170170
171- /**
172- * Remove a callable from the collection
173- *
174- * @param callable $callable
175- *
176- * @return $this
177- */
178- public function removeSortBy (callable $ callable )
179- {
180- $ res = array_search ($ callable , $ this ->iterator_sort_by , true );
181- unset($ this ->iterator_sort_by [$ res ]);
182-
183- return $ this ;
184- }
185-
186- /**
187- * Detect if the callable is already registered
188- *
189- * @param callable $callable
190- *
191- * @return bool
192- */
193- public function hasSortBy (callable $ callable )
194- {
195- return false !== array_search ($ callable , $ this ->iterator_sort_by , true );
196- }
197-
198- /**
199- * Remove all registered callable
200- *
201- * @return $this
202- */
203- public function clearSortBy ()
204- {
205- $ this ->iterator_sort_by = [];
206-
207- return $ this ;
208- }
209-
210171 /**
211172 * Set the Iterator filter method
212173 *
@@ -221,45 +182,6 @@ public function addFilter(callable $callable)
221182 return $ this ;
222183 }
223184
224- /**
225- * Remove a filter from the callable collection
226- *
227- * @param callable $callable
228- *
229- * @return $this
230- */
231- public function removeFilter (callable $ callable )
232- {
233- $ res = array_search ($ callable , $ this ->iterator_filters , true );
234- unset($ this ->iterator_filters [$ res ]);
235-
236- return $ this ;
237- }
238-
239- /**
240- * Detect if the callable filter is already registered
241- *
242- * @param callable $callable
243- *
244- * @return bool
245- */
246- public function hasFilter (callable $ callable )
247- {
248- return false !== array_search ($ callable , $ this ->iterator_filters , true );
249- }
250-
251- /**
252- * Remove all registered callable filter
253- *
254- * @return $this
255- */
256- public function clearFilter ()
257- {
258- $ this ->iterator_filters = [];
259-
260- return $ this ;
261- }
262-
263185 /**
264186 * Return the Iterator without the BOM sequence
265187 *
@@ -271,7 +193,7 @@ protected function getStripBomIterator(Iterator $iterator)
271193 {
272194 $ bom = $ this ->getInputBom ();
273195
274- return new MapIterator ( $ iterator , function ($ row , $ index ) use ($ bom ) {
196+ $ stripBom = function ($ row , $ index ) use ($ bom ) {
275197 if (0 == $ index ) {
276198 $ row [0 ] = mb_substr ($ row [0 ], mb_strlen ($ bom ));
277199 $ enclosure = $ this ->getEnclosure ();
@@ -282,7 +204,9 @@ protected function getStripBomIterator(Iterator $iterator)
282204 }
283205
284206 return $ row ;
285- });
207+ };
208+
209+ return new MapIterator ($ iterator , $ stripBom );
286210 }
287211
288212 /**
@@ -297,9 +221,10 @@ abstract public function getEnclosure();
297221 */
298222 protected function getQueryIterator ()
299223 {
300- array_unshift ( $ this -> iterator_filters , function ($ row ) {
224+ $ normalizedCsv = function ($ row ) {
301225 return is_array ($ row ) && $ row != [null ];
302- });
226+ };
227+ array_unshift ($ this ->iterator_filters , $ normalizedCsv );
303228 $ iterator = $ this ->getIterator ();
304229 $ iterator = $ this ->applyBomStripping ($ iterator );
305230 $ iterator = $ this ->applyIteratorFilter ($ iterator );
@@ -352,7 +277,7 @@ protected function applyIteratorFilter(Iterator $iterator)
352277 foreach ($ this ->iterator_filters as $ callable ) {
353278 $ iterator = new CallbackFilterIterator ($ iterator , $ callable );
354279 }
355- $ this ->clearFilter () ;
280+ $ this ->iterator_filters = [] ;
356281
357282 return $ iterator ;
358283 }
@@ -369,7 +294,9 @@ protected function applyIteratorSortBy(Iterator $iterator)
369294 if (!$ this ->iterator_sort_by ) {
370295 return $ iterator ;
371296 }
372- $ sortFunc = function ($ rowA , $ rowB ) {
297+
298+ $ obj = new ArrayObject (iterator_to_array ($ iterator ));
299+ $ obj ->uasort (function ($ rowA , $ rowB ) {
373300 $ sortRes = 0 ;
374301 foreach ($ this ->iterator_sort_by as $ callable ) {
375302 if (0 !== ($ sortRes = call_user_func ($ callable , $ rowA , $ rowB ))) {
@@ -378,11 +305,8 @@ protected function applyIteratorSortBy(Iterator $iterator)
378305 }
379306
380307 return $ sortRes ;
381- };
382-
383- $ obj = new ArrayObject (iterator_to_array ($ iterator ));
384- $ obj ->uasort ($ sortFunc );
385- $ this ->clearSortBy ();
308+ });
309+ $ this ->iterator_sort_by = [];
386310
387311 return $ obj ->getIterator ();
388312 }
0 commit comments