private function sort() { if (!$this->iteratorSorted && $this->isSorted()) { if (!$this->iterator instanceof \ArrayIterator) { $this->iterator = new \ArrayIterator(iterator_to_array($this->iterator)); } $this->iterator->uasort(function ($a, $b) { return $this->sortCriteria()->compare($a, $b); }); $this->iteratorSorted = true; } }