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