/** * @return void */ private function multiSort() { if (!$this->sortPended || empty($this->sortingCommands)) { return; } // set pended to false before toArray is performed to avoid infinite loop. $this->sortPended = false; $itArray = $this->it instanceof \ArrayIterator ? $this->it->getArrayCopy() : $this->toArray(); if (count($this->sortingCommands) === 1) { $command = $this->sortingCommands[0]; if (!is_null($command->getComparator())) { usort($itArray, function ($first, $second) use($command) { return -$command->getSortOrder() * $command->getComparator()->compare($first, $second); }); } else { if ($command->getSortOrder() === SortOrder::ASC) { sort($itArray); } else { rsort($itArray); } } } else { $itArray = $this->quickSort($itArray, $this->sortingCommands); } $this->it = new \ArrayIterator($itArray); }
/** * Get the item that's being traversed. * * @return \Traversable|array */ public function getTraversable() { if ($this->traversable instanceof ArrayIterator) { $array = $this->traversable->getArrayCopy(); for ($i = 0; $i < $this->i; $i++) { next($array); } return $array; } return $this->traversable; }
/** * Returns original data. * * @return array|\Traversable * * @throws DataException */ public function getRaw() { switch ($this->type) { case self::TYPE_ARRAY: return $this->data->getArrayCopy(); case self::TYPE_ITERATOR: return $this->data; case self::TYPE_AGGREGATE: return $this->data->getInnerIterator(); } throw DataException::invalidCollectionData($this->data); }