‪TYPO3CMS  10.4
ResourceUtility.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 {
34  public static function ‪recursiveFileListSortingHelper($elementA, $elementB)
35  {
36  if (strpos($elementA, '/') === false) {
37  // first element is a file
38  if (strpos($elementB, '/') === false) {
39  $result = ‪self::nameCompareSortingHelper($elementA, $elementB);
40  } else {
41  // second element is a directory => always sort it first
42  $result = 1;
43  }
44  } else {
45  // first element is a directory
46  if (strpos($elementB, '/') === false) {
47  // second element is a file => always sort it last
48  $result = -1;
49  } else {
50  // both elements are directories => we have to recursively sort here
51  [$pathPartA, $elementA] = explode('/', $elementA, 2);
52  [$pathPartB, $elementB] = explode('/', $elementB, 2);
53 
54  if ($pathPartA === $pathPartB) {
55  // same directory => sort by subpaths
56  $result = ‪self::recursiveFileListSortingHelper($elementA, $elementB);
57  } else {
58  // different directories => sort by current directories
59  $result = ‪self::nameCompareSortingHelper($pathPartA, $pathPartB);
60  }
61  }
62  }
63 
64  return $result;
65  }
66 
75  public static function ‪nameCompareSortingHelper($elementA, $elementB)
76  {
77  $result = strnatcasecmp($elementA, $elementB);
78  if ($result === 0) {
79  // Both are same in case insensitive so it's ok to check then now unnaturally.
80  $result = strcmp($elementA, $elementB);
81  }
82 
83  return $result;
84  }
85 }
‪TYPO3\CMS\Core\Utility\ResourceUtility\recursiveFileListSortingHelper
‪static int recursiveFileListSortingHelper($elementA, $elementB)
Definition: ResourceUtility.php:34
‪TYPO3\CMS\Core\Utility
Definition: ArrayUtility.php:16
‪TYPO3\CMS\Core\Utility\ResourceUtility\nameCompareSortingHelper
‪static int nameCompareSortingHelper($elementA, $elementB)
Definition: ResourceUtility.php:75
‪TYPO3\CMS\Core\Utility\ResourceUtility
Definition: ResourceUtility.php:22