1 | <?php |
||
19 | class Sort |
||
20 | { |
||
21 | /** @var \Collator[] language specific collators, usually only one */ |
||
22 | protected static $collator = []; |
||
23 | |||
24 | /** @var bool should the intl extension be used if available? For testing only */ |
||
25 | protected static $useIntl = true; |
||
26 | |||
27 | /** |
||
28 | * Initialization of a collator using $conf['lang'] as the locale. |
||
29 | * The initialization is done only once, except when $reload is set to true. |
||
30 | * The collation takes "natural ordering" into account, that is, "page 2" is before "page 10". |
||
31 | * |
||
32 | * @param bool $reload Usually false; true forces collator re-creation |
||
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($reload = false) |
||
57 | |||
58 | /** |
||
59 | * Enable or disable the use of the intl extension collator |
||
60 | * |
||
61 | * This is mostly used for testing and should not be used in normal code |
||
62 | * |
||
63 | * @param bool $use |
||
64 | */ |
||
65 | public static function useIntl($use = true) |
||
70 | |||
71 | /** |
||
72 | * Drop-in replacement for strcmp(), strcasecmp(), strnatcmp() and strnatcasecmp(). |
||
73 | * It uses a collator-based comparison, or strnatcasecmp() as a fallback. |
||
74 | * |
||
75 | * @param string $str1 The first string. |
||
76 | * @param string $str2 The second string. |
||
77 | * @return int Returns < 0 if $str1 is less than $str2; > 0 if $str1 is greater than $str2, and 0 if they are equal. |
||
78 | * |
||
79 | * @author Moisés Braga Ribeiro <[email protected]> |
||
80 | */ |
||
81 | public static function strcmp($str1, $str2) |
||
90 | |||
91 | /** |
||
92 | * Drop-in replacement for sort(). |
||
93 | * It uses a collator-based sort, or sort() with flags SORT_NATURAL and SORT_FLAG_CASE as a fallback. |
||
94 | * |
||
95 | * @param array $array The input array. |
||
96 | * @return bool Returns true on success or false on failure. |
||
97 | * |
||
98 | * @author Moisés Braga Ribeiro <[email protected]> |
||
99 | */ |
||
100 | public static function sort(&$array) |
||
109 | |||
110 | /** |
||
111 | * Drop-in replacement for ksort(). |
||
112 | * It uses a collator-based sort, or ksort() with flags SORT_NATURAL and SORT_FLAG_CASE as a fallback. |
||
113 | * |
||
114 | * @param array $array The input array. |
||
115 | * @return bool Returns true on success or false on failure. |
||
116 | * |
||
117 | * @author Moisés Braga Ribeiro <[email protected]> |
||
118 | */ |
||
119 | public static function ksort(&$array) |
||
128 | |||
129 | /** |
||
130 | * Drop-in replacement for asort(), natsort() and natcasesort(). |
||
131 | * It uses a collator-based sort, or asort() with flags SORT_NATURAL and SORT_FLAG_CASE as a fallback. |
||
132 | * |
||
133 | * @param array $array The input array. |
||
134 | * @return bool Returns true on success or false on failure. |
||
135 | * |
||
136 | * @author Moisés Braga Ribeiro <[email protected]> |
||
137 | */ |
||
138 | public static function asort(&$array) |
||
147 | |||
148 | /** |
||
149 | * Drop-in replacement for asort(), natsort() and natcasesort() when the parameter is an array of filenames. |
||
150 | * Filenames may not be equal to page names, depending on the setting in $conf['fnencode'], |
||
151 | * so the correct behavior is to sort page names and reflect this sorting in the filename array. |
||
152 | * |
||
153 | * @param array $array The input array. |
||
154 | * @return bool Returns true on success or false on failure. |
||
155 | * |
||
156 | * @author Moisés Braga Ribeiro <[email protected]> |
||
157 | */ |
||
158 | public static function asortFN(&$array) |
||
169 | |||
170 | } |
||
171 |