Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SortableDirectoryIterator extends RecursiveDirectoryIterator
- {
- /**
- * \ArrayObject
- */
- private $dirArray;
- public function __construct(string $path)
- {
- parent::__construct($path);
- $this->dirArray = new \ArrayObject();
- foreach($this as $item) {
- $this->dirArray->append( $item );
- }
- $this->dirArray->uasort( function ($fileObj1, $fileObj2) {
- if ($fileObj1->getMTime() == $fileObj2->getMTime()) {
- return 0;
- }
- return ($fileObj1->getMTime() < $fileObj2->getMTime()) ? -1 : 1;
- } );
- }
- public function getIterator()
- {
- return $this->dirArray->getIterator();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement