Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. class SortableDirectoryIterator extends RecursiveDirectoryIterator
  2. {
  3. /**
  4. * \ArrayObject
  5. */
  6. private $dirArray;
  7.  
  8. public function __construct(string $path)
  9. {
  10. parent::__construct($path);
  11. $this->dirArray = new \ArrayObject();
  12. foreach($this as $item) {
  13. $this->dirArray->append( $item );
  14. }
  15. $this->dirArray->uasort( function ($fileObj1, $fileObj2) {
  16. if ($fileObj1->getMTime() == $fileObj2->getMTime()) {
  17. return 0;
  18. }
  19. return ($fileObj1->getMTime() < $fileObj2->getMTime()) ? -1 : 1;
  20. } );
  21. }
  22.  
  23. public function getIterator()
  24. {
  25. return $this->dirArray->getIterator();
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement