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