3 declare(strict_types=1);
60 $order = $reverseOrder ? -1 : 1;
62 if (self::SORT_BY_NAME ===
$sort) {
64 $leftRealPath = $left->
getPath();
65 $rightRealPath = $right->getPath();
67 return $order * strcmp($leftRealPath, $rightRealPath);
69 } elseif (self::SORT_BY_NAME_NATURAL ===
$sort) {
71 $leftRealPath = $left->
getPath();
72 $rightRealPath = $right->getPath();
74 return $order * strnatcmp($leftRealPath, $rightRealPath);
76 } elseif (self::SORT_BY_TYPE ===
$sort) {
78 if ($left->
isDir() && $right->isFile()) {
80 } elseif ($left->
isFile() && $right->isDir()) {
84 $leftRealPath = $left->
getPath();
85 $rightRealPath = $right->getPath();
87 return $order * strcmp($leftRealPath, $rightRealPath);
89 } elseif (self::SORT_BY_TIME ===
$sort) {
92 $rightTimestamp = $this->
filesystem->getTimestamp($right->getPath());
94 return $order * ($leftTimestamp->getTimestamp() - $rightTimestamp->getTimestamp());
96 } elseif (self::SORT_BY_NONE ===
$sort) {
98 } elseif (is_callable(
$sort)) {
104 throw new InvalidArgumentException(
'The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.');
113 if (1 === $this->
sort) {
117 $array = iterator_to_array($this->iterator,
true);
118 if (-1 === $this->
sort) {
119 $array = array_reverse($array);
121 uasort($array, $this->
sort);
__construct(Filesystem $filesystem, Traversable $iterator, $sort, $reverseOrder=false)
Sortable constructor.
sort(Closure $closure)
Sorts files and directories by an anonymous function.
const SORT_BY_NAME_NATURAL
Class FlySystemFileAccessTest disabled disabled disabled.