From: Vincent Vanwaelscappel Date: Fri, 24 Dec 2021 16:47:05 +0000 (+0100) Subject: wip #4978 @0.25 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=0892ce272dc3da4ec5a0d8a54c4380ca19e65d58;p=cubist_util.git wip #4978 @0.25 --- diff --git a/src/Files/DirectorySortedIterator.php b/src/Files/DirectorySortedIterator.php index 4d56c5c..de2c87a 100644 --- a/src/Files/DirectorySortedIterator.php +++ b/src/Files/DirectorySortedIterator.php @@ -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()); + } }