From 0892ce272dc3da4ec5a0d8a54c4380ca19e65d58 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 24 Dec 2021 17:47:05 +0100 Subject: [PATCH] wip #4978 @0.25 --- src/Files/DirectorySortedIterator.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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()); + } } -- 2.39.5