PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / lib / packages / Safe / generated / array.php

array.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at lib/packages/Safe/generated/array.php

465 lines 13.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WP_DEFENDER_VENDOR\Safe;
4
5 use WP_DEFENDER_VENDOR\Safe\Exceptions\ArrayException;
6
7 /**
8 * Creates an array by using the values from the
9 * keys array as keys and the values from the
10 * values array as the corresponding values.
11 *
12 * @param array $keys Array of keys to be used. Illegal values for key will be
13 * converted to string.
14 * @param array $values Array of values to be used
15 * @return array Returns the combined array, FALSE if the number of elements
16 * for each array isn't equal.
17 * @throws ArrayException
18 *
19 */
20 function array_combine(array $keys, array $values): array
21 {
22 error_clear_last();
23 $result = \array_combine($keys, $values);
24 if ($result === false) {
25 throw ArrayException::createFromPhpError();
26 }
27 return $result;
28 }
29
30
31 /**
32 * array_flip returns an array in flip
33 * order, i.e. keys from array become values and values
34 * from array become keys.
35 *
36 * Note that the values of array need to be valid
37 * keys, i.e. they need to be either integer or
38 * string. A warning will be emitted if a value has the wrong
39 * type, and the key/value pair in question will not be included
40 * in the result.
41 *
42 * If a value has several occurrences, the latest key will be
43 * used as its value, and all others will be lost.
44 *
45 * @param array $array An array of key/value pairs to be flipped.
46 * @return array Returns the flipped array on success.
47 * @throws ArrayException
48 *
49 */
50 function array_flip(array $array): array
51 {
52 error_clear_last();
53 $result = \array_flip($array);
54 if ($result === null) {
55 throw ArrayException::createFromPhpError();
56 }
57 return $result;
58 }
59
60
61 /**
62 * array_replace_recursive replaces the values of
63 * array1 with the same values from all the following
64 * arrays. If a key from the first array exists in the second array, its value
65 * will be replaced by the value from the second array. If the key exists in the
66 * second array, and not the first, it will be created in the first array.
67 * If a key only exists in the first array, it will be left as is.
68 * If several arrays are passed for replacement, they will be processed
69 * in order, the later array overwriting the previous values.
70 *
71 * array_replace_recursive is recursive : it will recurse into
72 * arrays and apply the same process to the inner value.
73 *
74 * When the value in the first array is scalar, it will be replaced
75 * by the value in the second array, may it be scalar or array.
76 * When the value in the first array and the second array
77 * are both arrays, array_replace_recursive will replace
78 * their respective value recursively.
79 *
80 * @param array $array1 The array in which elements are replaced.
81 * @param array $params Optional. Arrays from which elements will be extracted.
82 * @return array Returns an array.
83 * @throws ArrayException
84 *
85 */
86 function array_replace_recursive(array $array1, array ...$params): array
87 {
88 error_clear_last();
89 if ($params !== []) {
90 $result = \array_replace_recursive($array1, ...$params);
91 } else {
92 $result = \array_replace_recursive($array1);
93 }
94 if ($result === null) {
95 throw ArrayException::createFromPhpError();
96 }
97 return $result;
98 }
99
100
101 /**
102 * array_replace replaces the values of
103 * array1 with values having the same keys in each of the following
104 * arrays. If a key from the first array exists in the second array, its value
105 * will be replaced by the value from the second array. If the key exists in the
106 * second array, and not the first, it will be created in the first array.
107 * If a key only exists in the first array, it will be left as is.
108 * If several arrays are passed for replacement, they will be processed
109 * in order, the later arrays overwriting the previous values.
110 *
111 * array_replace is not recursive : it will replace
112 * values in the first array by whatever type is in the second array.
113 *
114 * @param array $array1 The array in which elements are replaced.
115 * @param array $params Arrays from which elements will be extracted.
116 * Values from later arrays overwrite the previous values.
117 * @return array Returns an array.
118 * @throws ArrayException
119 *
120 */
121 function array_replace(array $array1, array ...$params): array
122 {
123 error_clear_last();
124 if ($params !== []) {
125 $result = \array_replace($array1, ...$params);
126 } else {
127 $result = \array_replace($array1);
128 }
129 if ($result === null) {
130 throw ArrayException::createFromPhpError();
131 }
132 return $result;
133 }
134
135
136 /**
137 * Applies the user-defined callback function to each
138 * element of the array. This function will recurse
139 * into deeper arrays.
140 *
141 * @param array $array The input array.
142 * @param callable $callback Typically, callback takes on two parameters.
143 * The array parameter's value being the first, and
144 * the key/index second.
145 *
146 * If callback needs to be working with the
147 * actual values of the array, specify the first parameter of
148 * callback as a
149 * reference. Then,
150 * any changes made to those elements will be made in the
151 * original array itself.
152 * @param mixed $userdata If the optional userdata parameter is supplied,
153 * it will be passed as the third parameter to the
154 * callback.
155 * @throws ArrayException
156 *
157 */
158 function array_walk_recursive(array &$array, callable $callback, $userdata = null): void
159 {
160 error_clear_last();
161 $result = \array_walk_recursive($array, $callback, $userdata);
162 if ($result === false) {
163 throw ArrayException::createFromPhpError();
164 }
165 }
166
167
168 /**
169 * This function sorts an array such that array indices maintain their
170 * correlation with the array elements they are associated with.
171 *
172 * This is used mainly when sorting associative arrays where the actual
173 * element order is significant.
174 *
175 * @param array $array The input array.
176 * @param int $sort_flags You may modify the behavior of the sort using the optional parameter
177 * sort_flags, for details see
178 * sort.
179 * @throws ArrayException
180 *
181 */
182 function arsort(array &$array, int $sort_flags = SORT_REGULAR): void
183 {
184 error_clear_last();
185 $result = \arsort($array, $sort_flags);
186 if ($result === false) {
187 throw ArrayException::createFromPhpError();
188 }
189 }
190
191
192 /**
193 * This function sorts an array such that array indices maintain
194 * their correlation with the array elements they are associated
195 * with. This is used mainly when sorting associative arrays where
196 * the actual element order is significant.
197 *
198 * @param array $array The input array.
199 * @param int $sort_flags You may modify the behavior of the sort using the optional
200 * parameter sort_flags, for details
201 * see sort.
202 * @throws ArrayException
203 *
204 */
205 function asort(array &$array, int $sort_flags = SORT_REGULAR): void
206 {
207 error_clear_last();
208 $result = \asort($array, $sort_flags);
209 if ($result === false) {
210 throw ArrayException::createFromPhpError();
211 }
212 }
213
214
215 /**
216 * Sorts an array by key in reverse order, maintaining key to data
217 * correlations. This is useful mainly for associative arrays.
218 *
219 * @param array $array The input array.
220 * @param int $sort_flags You may modify the behavior of the sort using the optional parameter
221 * sort_flags, for details see
222 * sort.
223 * @throws ArrayException
224 *
225 */
226 function krsort(array &$array, int $sort_flags = SORT_REGULAR): void
227 {
228 error_clear_last();
229 $result = \krsort($array, $sort_flags);
230 if ($result === false) {
231 throw ArrayException::createFromPhpError();
232 }
233 }
234
235
236 /**
237 * Sorts an array by key, maintaining key to data correlations. This is
238 * useful mainly for associative arrays.
239 *
240 * @param array $array The input array.
241 * @param int $sort_flags You may modify the behavior of the sort using the optional
242 * parameter sort_flags, for details
243 * see sort.
244 * @throws ArrayException
245 *
246 */
247 function ksort(array &$array, int $sort_flags = SORT_REGULAR): void
248 {
249 error_clear_last();
250 $result = \ksort($array, $sort_flags);
251 if ($result === false) {
252 throw ArrayException::createFromPhpError();
253 }
254 }
255
256
257 /**
258 * natcasesort is a case insensitive version of
259 * natsort.
260 *
261 * This function implements a sort algorithm that orders
262 * alphanumeric strings in the way a human being would while maintaining
263 * key/value associations. This is described as a "natural ordering".
264 *
265 * @param array $array The input array.
266 * @throws ArrayException
267 *
268 */
269 function natcasesort(array &$array): void
270 {
271 error_clear_last();
272 $result = \natcasesort($array);
273 if ($result === false) {
274 throw ArrayException::createFromPhpError();
275 }
276 }
277
278
279 /**
280 * This function implements a sort algorithm that orders alphanumeric strings
281 * in the way a human being would while maintaining key/value associations.
282 * This is described as a "natural ordering". An example of the difference
283 * between this algorithm and the regular computer string sorting algorithms
284 * (used in sort) can be seen in the example below.
285 *
286 * @param array $array The input array.
287 * @throws ArrayException
288 *
289 */
290 function natsort(array &$array): void
291 {
292 error_clear_last();
293 $result = \natsort($array);
294 if ($result === false) {
295 throw ArrayException::createFromPhpError();
296 }
297 }
298
299
300 /**
301 * This function sorts an array in reverse order (highest to lowest).
302 *
303 * @param array $array The input array.
304 * @param int $sort_flags You may modify the behavior of the sort using the optional
305 * parameter sort_flags, for details see
306 * sort.
307 * @throws ArrayException
308 *
309 */
310 function rsort(array &$array, int $sort_flags = SORT_REGULAR): void
311 {
312 error_clear_last();
313 $result = \rsort($array, $sort_flags);
314 if ($result === false) {
315 throw ArrayException::createFromPhpError();
316 }
317 }
318
319
320 /**
321 * This function shuffles (randomizes the order of the elements in) an array.
322 * It uses a pseudo random number generator that is not suitable for
323 * cryptographic purposes.
324 *
325 * @param array $array The array.
326 * @throws ArrayException
327 *
328 */
329 function shuffle(array &$array): void
330 {
331 error_clear_last();
332 $result = \shuffle($array);
333 if ($result === false) {
334 throw ArrayException::createFromPhpError();
335 }
336 }
337
338
339 /**
340 * This function sorts an array. Elements will be arranged from
341 * lowest to highest when this function has completed.
342 *
343 * @param array $array The input array.
344 * @param int $sort_flags The optional second parameter sort_flags
345 * may be used to modify the sorting behavior using these values:
346 *
347 * Sorting type flags:
348 *
349 *
350 * SORT_REGULAR - compare items normally;
351 * the details are described in the comparison operators section
352 *
353 *
354 * SORT_NUMERIC - compare items numerically
355 *
356 *
357 * SORT_STRING - compare items as strings
358 *
359 *
360 *
361 * SORT_LOCALE_STRING - compare items as
362 * strings, based on the current locale. It uses the locale,
363 * which can be changed using setlocale
364 *
365 *
366 *
367 *
368 * SORT_NATURAL - compare items as strings
369 * using "natural ordering" like natsort
370 *
371 *
372 *
373 *
374 * SORT_FLAG_CASE - can be combined
375 * (bitwise OR) with
376 * SORT_STRING or
377 * SORT_NATURAL to sort strings case-insensitively
378 *
379 *
380 *
381 * @throws ArrayException
382 *
383 */
384 function sort(array &$array, int $sort_flags = SORT_REGULAR): void
385 {
386 error_clear_last();
387 $result = \sort($array, $sort_flags);
388 if ($result === false) {
389 throw ArrayException::createFromPhpError();
390 }
391 }
392
393
394 /**
395 * This function sorts an array such that array indices maintain their
396 * correlation with the array elements they are associated with, using a
397 * user-defined comparison function.
398 *
399 * This is used mainly when sorting associative arrays where the actual
400 * element order is significant.
401 *
402 * @param array $array The input array.
403 * @param callable $value_compare_func See usort and uksort for
404 * examples of user-defined comparison functions.
405 * @throws ArrayException
406 *
407 */
408 function uasort(array &$array, callable $value_compare_func): void
409 {
410 error_clear_last();
411 $result = \uasort($array, $value_compare_func);
412 if ($result === false) {
413 throw ArrayException::createFromPhpError();
414 }
415 }
416
417
418 /**
419 * uksort will sort the keys of an array using a
420 * user-supplied comparison function. If the array you wish to sort
421 * needs to be sorted by some non-trivial criteria, you should use
422 * this function.
423 *
424 * @param array $array The input array.
425 * @param callable $key_compare_func The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
426 * Note that before PHP 7.0.0 this integer had to be in the range from -2147483648 to 2147483647.
427 * @throws ArrayException
428 *
429 */
430 function uksort(array &$array, callable $key_compare_func): void
431 {
432 error_clear_last();
433 $result = \uksort($array, $key_compare_func);
434 if ($result === false) {
435 throw ArrayException::createFromPhpError();
436 }
437 }
438
439
440 /**
441 * This function will sort an array by its values using a user-supplied
442 * comparison function. If the array you wish to sort needs to be sorted by
443 * some non-trivial criteria, you should use this function.
444 *
445 * @param array $array The input array.
446 * @param callable $value_compare_func The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
447 * Note that before PHP 7.0.0 this integer had to be in the range from -2147483648 to 2147483647.
448 *
449 * Returning non-integer values from the comparison
450 * function, such as float, will result in an internal cast to
451 * integer of the callback's return value. So values such as
452 * 0.99 and 0.1 will both be cast to an integer value of 0, which will
453 * compare such values as equal.
454 * @throws ArrayException
455 *
456 */
457 function usort(array &$array, callable $value_compare_func): void
458 {
459 error_clear_last();
460 $result = \usort($array, $value_compare_func);
461 if ($result === false) {
462 throw ArrayException::createFromPhpError();
463 }
464 }
465