1 | <?php |
||
20 | class Sort |
||
21 | { |
||
22 | /** @var \Collator[] language specific collators, usually only one */ |
||
23 | protected static $collators = []; |
||
24 | |||
25 | /** @var bool should the intl extension be used if available? For testing only */ |
||
26 | protected static $useIntl = true; |
||
27 | |||
28 | /** |
||
29 | * Initialization of a collator using $conf['lang'] as the locale. |
||
30 | * The initialization is done only once. |
||
31 | * The collation takes "natural ordering" into account, that is, "page 2" is before "page 10". |
||
32 | * |
||
33 | * @return \Collator Returns a configured collator or null if the collator cannot be created. |
||
34 | * |
||
35 | * @author Moisés Braga Ribeiro <[email protected]> |
||
36 | */ |
||
37 | protected static function getCollator() |
||
60 | |||
61 | /** |
||
62 | * Enable or disable the use of the "intl" extension collator. |
||
63 | * This is used for testing and should not be used in normal code. |
||
64 | * |
||
65 | * @param bool $use |
||
66 | * |
||
67 | * @author Andreas Gohr <[email protected]> |
||
68 | */ |
||
69 | public static function useIntl($use = true) |
||
73 | |||
74 | /** |
||
75 | * Drop-in replacement for strcmp(), strcasecmp(), strnatcmp() and strnatcasecmp(). |
||
76 | * It uses a collator-based comparison, or strnatcasecmp() as a fallback. |
||
77 | * |
||
78 | * @param string $str1 The first string. |
||
79 | * @param string $str2 The second string. |
||
80 | * @return int Returns < 0 if $str1 is less than $str2; > 0 if $str1 is greater than $str2, and 0 if they are equal. |
||
81 | * |
||
82 | * @author Moisés Braga Ribeiro <[email protected]> |
||
83 | */ |
||
84 | public static function strcmp($str1, $str2) |
||
93 | |||
94 | /** |
||
95 | * Drop-in replacement for sort(). |
||
96 | * It uses a collator-based sort, or sort() with flags SORT_NATURAL and SORT_FLAG_CASE as a fallback. |
||
97 | * |
||
98 | * @param array $array The input array. |
||
99 | * @return bool Returns true on success or false on failure. |
||
100 | * |
||
101 | * @author Moisés Braga Ribeiro <[email protected]> |
||
102 | */ |
||
103 | public static function sort(&$array) |
||
112 | |||
113 | /** |
||
114 | * Drop-in replacement for ksort(). |
||
115 | * It uses a collator-based sort, or ksort() with flags SORT_NATURAL and SORT_FLAG_CASE as a fallback. |
||
116 | * |
||
117 | * @param array $array The input array. |
||
118 | * @return bool Returns true on success or false on failure. |
||
119 | * |
||
120 | * @author Moisés Braga Ribeiro <[email protected]> |
||
121 | */ |
||
122 | public static function ksort(&$array) |
||
131 | |||
132 | /** |
||
133 | * Drop-in replacement for asort(), natsort() and natcasesort(). |
||
134 | * It uses a collator-based sort, or asort() with flags SORT_NATURAL and SORT_FLAG_CASE as a fallback. |
||
135 | * |
||
136 | * @param array $array The input array. |
||
137 | * @return bool Returns true on success or false on failure. |
||
138 | * |
||
139 | * @author Moisés Braga Ribeiro <[email protected]> |
||
140 | */ |
||
141 | public static function asort(&$array) |
||
150 | |||
151 | /** |
||
152 | * Drop-in replacement for asort(), natsort() and natcasesort() when the parameter is an array of filenames. |
||
153 | * Filenames may not be equal to page names, depending on the setting in $conf['fnencode'], |
||
154 | * so the correct behavior is to sort page names and reflect this sorting in the filename array. |
||
155 | * |
||
156 | * @param array $array The input array. |
||
157 | * @return bool Returns true on success or false on failure. |
||
158 | * |
||
159 | * @author Moisés Braga Ribeiro <[email protected]> |
||
160 | * @author Andreas Gohr <[email protected]> |
||
161 | */ |
||
162 | public static function asortFN(&$array) |
||
173 | } |
||
174 |