]> _ Git - cubist_util.git/commitdiff
wip #4978 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 24 Dec 2021 16:47:05 +0000 (17:47 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 24 Dec 2021 16:47:05 +0000 (17:47 +0100)
src/Files/DirectorySortedIterator.php

index 4d56c5c2eacd2cc0a82890d23b4e6c8560714a9f..de2c87aa337786f7c330b38fa314c2ae5ff1d3a0 100644 (file)
@@ -7,14 +7,19 @@ use SplHeap;
 
 class DirectorySortedIterator extends SplHeap
 {
-    public function __construct(Iterator $iterator)
+    protected $way = 1;
+
+    public function __construct(Iterator $iterator, $reversed = false)
     {
+        $this->way = $reversed ? -1 : 1;
         foreach ($iterator as $item) {
             $this->insert($item);
         }
     }
-    public function compare($b,$a)
+
+    public function compare($b, $a)
     {
-        return strcmp($a->getRealpath(), $b->getRealpath());
+        return $this->way * strcmp($a->getRealpath(), $b->getRealpath());
+
     }
 }