public function getIterator()
{
// Convert the source to an array, for sorting.
if ($this->source instanceof Traversable) {
$data = iterator_to_array($this->source);
} elseif (is_array($this->source)) {
$data = $this->source;
} else {
throw new InvalidStreamException("Cannot handle stream of type " . gettype($this->source));
}
if ($this->sort != null) {
uasort($data, $this->sort);
} else {
asort($data);
}
return new ArrayIterator($data);
}