19 declare(strict_types=1);
58 $order = $reverseOrder ? -1 : 1;
60 if (self::SORT_BY_NAME ===
$sort) {
62 $leftRealPath = $left->
getPath();
63 $rightRealPath = $right->getPath();
65 return $order * strcmp($leftRealPath, $rightRealPath);
67 } elseif (self::SORT_BY_NAME_NATURAL ===
$sort) {
69 $leftRealPath = $left->
getPath();
70 $rightRealPath = $right->getPath();
72 return $order * strnatcmp($leftRealPath, $rightRealPath);
74 } elseif (self::SORT_BY_TYPE ===
$sort) {
76 if ($left->
isDir() && $right->isFile()) {
79 if ($left->
isFile() && $right->isDir()) {
83 $leftRealPath = $left->
getPath();
84 $rightRealPath = $right->getPath();
86 return $order * strcmp($leftRealPath, $rightRealPath);
88 } elseif (self::SORT_BY_TIME ===
$sort) {
91 $rightTimestamp = $this->
filesystem->getTimestamp($right->getPath());
93 return $order * ($leftTimestamp->getTimestamp() - $rightTimestamp->getTimestamp());
95 } elseif (self::SORT_BY_NONE ===
$sort) {
97 } elseif (is_callable(
$sort)) {
104 'The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.' 114 if (1 === $this->
sort) {
115 return $this->iterator;
118 $array = iterator_to_array($this->iterator,
true);
119 if (-1 === $this->
sort) {
120 $array = array_reverse($array);
122 uasort($array, $this->
sort);
__construct(private Filesystem $filesystem, private Traversable $iterator, $sort, $reverseOrder=false)
Sortable constructor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
sort(Closure $closure)
Sorts files and directories by an anonymous function.
const SORT_BY_NAME_NATURAL