note 104735 deleted from class.directoryiterator by danbrown
| From: | danbrown@php.net | Date: | Tue, 05 Jul 2011 13:40:20 +0000 |
| Subject: | note 104735 deleted from class.directoryiterator by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-181244@lists.php.net to get a copy of this message | ||
Note Submitter: sergey dot tsivin at NOSPAM dot com
----
Here's a way to create sortable iterator, thanks to Philipp W. gnurepublic_at_linuxmail.org and
Michelangelo van Dam.
<?php
class SortableDirectoryIterator implements IteratorAggregate
{
private $_storage;
public function __construct($path)
{
$this->_storage = new ArrayObject();
$files = new DirectoryIterator($path);
foreach ($files as $file) {
$this->_storage->offsetSet($file->getFilename(), $file->getFileInfo());
}
$this->_storage->uksort(
function ($a, $b) {
return strcmp($a, $b);
}
);
}
public function getIterator()
{
return $this->_storage->getIterator();
}
}
?>