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
misc.php
442 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePressVendor\Safe; |
| 4 | |
| 5 | use ProfilePressVendor\Safe\Exceptions\MiscException; |
| 6 | /** |
| 7 | * Defines a named constant at runtime. |
| 8 | * |
| 9 | * @param string $name The name of the constant. |
| 10 | * |
| 11 | * It is possible to define constants with reserved or |
| 12 | * even invalid names, whose value can (only) be retrieved with |
| 13 | * constant. However, doing so is not recommended. |
| 14 | * @param mixed $value The value of the constant. In PHP 5, value must |
| 15 | * be a scalar value (integer, |
| 16 | * float, string, boolean, or |
| 17 | * NULL). In PHP 7, array values are also accepted. |
| 18 | * |
| 19 | * While it is possible to define resource constants, it is |
| 20 | * not recommended and may cause unpredictable behavior. |
| 21 | * @param bool $case_insensitive If set to TRUE, the constant will be defined case-insensitive. |
| 22 | * The default behavior is case-sensitive; i.e. |
| 23 | * CONSTANT and Constant represent |
| 24 | * different values. |
| 25 | * |
| 26 | * Case-insensitive constants are stored as lower-case. |
| 27 | * @throws MiscException |
| 28 | * |
| 29 | */ |
| 30 | function define(string $name, $value, bool $case_insensitive = \false): void |
| 31 | { |
| 32 | error_clear_last(); |
| 33 | $result = \define($name, $value, $case_insensitive); |
| 34 | if ($result === \false) { |
| 35 | throw MiscException::createFromPhpError(); |
| 36 | } |
| 37 | } |
| 38 | /** |
| 39 | * Prints out or returns a syntax highlighted version of the code contained |
| 40 | * in filename using the colors defined in the |
| 41 | * built-in syntax highlighter for PHP. |
| 42 | * |
| 43 | * Many servers are configured to automatically highlight files |
| 44 | * with a phps extension. For example, |
| 45 | * example.phps when viewed will show the |
| 46 | * syntax highlighted source of the file. To enable this, add this |
| 47 | * line to the httpd.conf: |
| 48 | * |
| 49 | * @param string $filename Path to the PHP file to be highlighted. |
| 50 | * @param bool $return Set this parameter to TRUE to make this function return the |
| 51 | * highlighted code. |
| 52 | * @return string|bool If return is set to TRUE, returns the highlighted |
| 53 | * code as a string instead of printing it out. Otherwise, it will return |
| 54 | * TRUE on success, FALSE on failure. |
| 55 | * @throws MiscException |
| 56 | * |
| 57 | */ |
| 58 | function highlight_file(string $filename, bool $return = \false) |
| 59 | { |
| 60 | error_clear_last(); |
| 61 | $result = \highlight_file($filename, $return); |
| 62 | if ($result === \false) { |
| 63 | throw MiscException::createFromPhpError(); |
| 64 | } |
| 65 | return $result; |
| 66 | } |
| 67 | /** |
| 68 | * |
| 69 | * |
| 70 | * @param string $str The PHP code to be highlighted. This should include the opening tag. |
| 71 | * @param bool $return Set this parameter to TRUE to make this function return the |
| 72 | * highlighted code. |
| 73 | * @return string|bool If return is set to TRUE, returns the highlighted |
| 74 | * code as a string instead of printing it out. Otherwise, it will return |
| 75 | * TRUE on success, FALSE on failure. |
| 76 | * @throws MiscException |
| 77 | * |
| 78 | */ |
| 79 | function highlight_string(string $str, bool $return = \false) |
| 80 | { |
| 81 | error_clear_last(); |
| 82 | $result = \highlight_string($str, $return); |
| 83 | if ($result === \false) { |
| 84 | throw MiscException::createFromPhpError(); |
| 85 | } |
| 86 | return $result; |
| 87 | } |
| 88 | /** |
| 89 | * Pack given arguments into a binary string according to |
| 90 | * format. |
| 91 | * |
| 92 | * The idea for this function was taken from Perl and all formatting codes |
| 93 | * work the same as in Perl. However, there are some formatting codes that are |
| 94 | * missing such as Perl's "u" format code. |
| 95 | * |
| 96 | * Note that the distinction between signed and unsigned values only |
| 97 | * affects the function unpack, where as |
| 98 | * function pack gives the same result for |
| 99 | * signed and unsigned format codes. |
| 100 | * |
| 101 | * @param string $format The format string consists of format codes |
| 102 | * followed by an optional repeater argument. The repeater argument can |
| 103 | * be either an integer value or * for repeating to |
| 104 | * the end of the input data. For a, A, h, H the repeat count specifies |
| 105 | * how many characters of one data argument are taken, for @ it is the |
| 106 | * absolute position where to put the next data, for everything else the |
| 107 | * repeat count specifies how many data arguments are consumed and packed |
| 108 | * into the resulting binary string. |
| 109 | * |
| 110 | * Currently implemented formats are: |
| 111 | * |
| 112 | * pack format characters |
| 113 | * |
| 114 | * |
| 115 | * |
| 116 | * Code |
| 117 | * Description |
| 118 | * |
| 119 | * |
| 120 | * |
| 121 | * |
| 122 | * a |
| 123 | * NUL-padded string |
| 124 | * |
| 125 | * |
| 126 | * A |
| 127 | * SPACE-padded string |
| 128 | * |
| 129 | * h |
| 130 | * Hex string, low nibble first |
| 131 | * |
| 132 | * H |
| 133 | * Hex string, high nibble first |
| 134 | * csigned char |
| 135 | * |
| 136 | * C |
| 137 | * unsigned char |
| 138 | * |
| 139 | * s |
| 140 | * signed short (always 16 bit, machine byte order) |
| 141 | * |
| 142 | * |
| 143 | * S |
| 144 | * unsigned short (always 16 bit, machine byte order) |
| 145 | * |
| 146 | * |
| 147 | * n |
| 148 | * unsigned short (always 16 bit, big endian byte order) |
| 149 | * |
| 150 | * |
| 151 | * v |
| 152 | * unsigned short (always 16 bit, little endian byte order) |
| 153 | * |
| 154 | * |
| 155 | * i |
| 156 | * signed integer (machine dependent size and byte order) |
| 157 | * |
| 158 | * |
| 159 | * I |
| 160 | * unsigned integer (machine dependent size and byte order) |
| 161 | * |
| 162 | * |
| 163 | * l |
| 164 | * signed long (always 32 bit, machine byte order) |
| 165 | * |
| 166 | * |
| 167 | * L |
| 168 | * unsigned long (always 32 bit, machine byte order) |
| 169 | * |
| 170 | * |
| 171 | * N |
| 172 | * unsigned long (always 32 bit, big endian byte order) |
| 173 | * |
| 174 | * |
| 175 | * V |
| 176 | * unsigned long (always 32 bit, little endian byte order) |
| 177 | * |
| 178 | * |
| 179 | * q |
| 180 | * signed long long (always 64 bit, machine byte order) |
| 181 | * |
| 182 | * |
| 183 | * Q |
| 184 | * unsigned long long (always 64 bit, machine byte order) |
| 185 | * |
| 186 | * |
| 187 | * J |
| 188 | * unsigned long long (always 64 bit, big endian byte order) |
| 189 | * |
| 190 | * |
| 191 | * P |
| 192 | * unsigned long long (always 64 bit, little endian byte order) |
| 193 | * |
| 194 | * |
| 195 | * f |
| 196 | * float (machine dependent size and representation) |
| 197 | * |
| 198 | * |
| 199 | * g |
| 200 | * float (machine dependent size, little endian byte order) |
| 201 | * |
| 202 | * |
| 203 | * G |
| 204 | * float (machine dependent size, big endian byte order) |
| 205 | * |
| 206 | * |
| 207 | * d |
| 208 | * double (machine dependent size and representation) |
| 209 | * |
| 210 | * |
| 211 | * e |
| 212 | * double (machine dependent size, little endian byte order) |
| 213 | * |
| 214 | * |
| 215 | * E |
| 216 | * double (machine dependent size, big endian byte order) |
| 217 | * |
| 218 | * |
| 219 | * x |
| 220 | * NUL byte |
| 221 | * |
| 222 | * |
| 223 | * X |
| 224 | * Back up one byte |
| 225 | * |
| 226 | * |
| 227 | * Z |
| 228 | * NUL-padded string (new in PHP 5.5) |
| 229 | * |
| 230 | * |
| 231 | * @ |
| 232 | * NUL-fill to absolute position |
| 233 | * |
| 234 | * |
| 235 | * |
| 236 | * |
| 237 | * @param mixed $params |
| 238 | * @return string Returns a binary string containing data. |
| 239 | * @throws MiscException |
| 240 | * |
| 241 | */ |
| 242 | function pack(string $format, ...$params): string |
| 243 | { |
| 244 | error_clear_last(); |
| 245 | if ($params !== []) { |
| 246 | $result = \pack($format, ...$params); |
| 247 | } else { |
| 248 | $result = \pack($format); |
| 249 | } |
| 250 | if ($result === \false) { |
| 251 | throw MiscException::createFromPhpError(); |
| 252 | } |
| 253 | return $result; |
| 254 | } |
| 255 | /** |
| 256 | * Convert string from one codepage to another. |
| 257 | * |
| 258 | * @param int|string $in_codepage The codepage of the subject string. |
| 259 | * Either the codepage name or identifier. |
| 260 | * @param int|string $out_codepage The codepage to convert the subject string to. |
| 261 | * Either the codepage name or identifier. |
| 262 | * @param string $subject The string to convert. |
| 263 | * @return string The subject string converted to |
| 264 | * out_codepage. |
| 265 | * @throws MiscException |
| 266 | * |
| 267 | */ |
| 268 | function sapi_windows_cp_conv($in_codepage, $out_codepage, string $subject): string |
| 269 | { |
| 270 | error_clear_last(); |
| 271 | $result = \sapi_windows_cp_conv($in_codepage, $out_codepage, $subject); |
| 272 | if ($result === null) { |
| 273 | throw MiscException::createFromPhpError(); |
| 274 | } |
| 275 | return $result; |
| 276 | } |
| 277 | /** |
| 278 | * Set the codepage of the current process. |
| 279 | * |
| 280 | * @param int $cp A codepage identifier. |
| 281 | * @throws MiscException |
| 282 | * |
| 283 | */ |
| 284 | function sapi_windows_cp_set(int $cp): void |
| 285 | { |
| 286 | error_clear_last(); |
| 287 | $result = \sapi_windows_cp_set($cp); |
| 288 | if ($result === \false) { |
| 289 | throw MiscException::createFromPhpError(); |
| 290 | } |
| 291 | } |
| 292 | /** |
| 293 | * Sends a CTRL event to another process in the same process group. |
| 294 | * |
| 295 | * @param int $event The CTRL even to send; |
| 296 | * either PHP_WINDOWS_EVENT_CTRL_C |
| 297 | * or PHP_WINDOWS_EVENT_CTRL_BREAK. |
| 298 | * @param int $pid The ID of the process to which to send the event to. If 0 |
| 299 | * is given, the event is sent to all processes of the process group. |
| 300 | * @throws MiscException |
| 301 | * |
| 302 | */ |
| 303 | function sapi_windows_generate_ctrl_event(int $event, int $pid = 0): void |
| 304 | { |
| 305 | error_clear_last(); |
| 306 | $result = \sapi_windows_generate_ctrl_event($event, $pid); |
| 307 | if ($result === \false) { |
| 308 | throw MiscException::createFromPhpError(); |
| 309 | } |
| 310 | } |
| 311 | /** |
| 312 | * If enable is omitted, the function returns TRUE if the stream stream has VT100 control codes enabled, FALSE otherwise. |
| 313 | * |
| 314 | * If enable is specified, the function will try to enable or disable the VT100 features of the stream stream. |
| 315 | * If the feature has been successfully enabled (or disabled). |
| 316 | * |
| 317 | * At startup, PHP tries to enable the VT100 feature of the STDOUT/STDERR streams. By the way, if those streams are redirected to a file, the VT100 features may not be enabled. |
| 318 | * |
| 319 | * If VT100 support is enabled, it is possible to use control sequences as they are known from the VT100 terminal. |
| 320 | * They allow the modification of the terminal's output. On Windows these sequences are called Console Virtual Terminal Sequences. |
| 321 | * |
| 322 | * @param resource $stream The stream on which the function will operate. |
| 323 | * @param bool $enable If specified, the VT100 feature will be enabled (if TRUE) or disabled (if FALSE). |
| 324 | * @throws MiscException |
| 325 | * |
| 326 | */ |
| 327 | function sapi_windows_vt100_support($stream, bool $enable = null): void |
| 328 | { |
| 329 | error_clear_last(); |
| 330 | if ($enable !== null) { |
| 331 | $result = \sapi_windows_vt100_support($stream, $enable); |
| 332 | } else { |
| 333 | $result = \sapi_windows_vt100_support($stream); |
| 334 | } |
| 335 | if ($result === \false) { |
| 336 | throw MiscException::createFromPhpError(); |
| 337 | } |
| 338 | } |
| 339 | /** |
| 340 | * |
| 341 | * |
| 342 | * @param int $seconds Halt time in seconds. |
| 343 | * @return int Returns zero on success. |
| 344 | * |
| 345 | * If the call was interrupted by a signal, sleep returns |
| 346 | * a non-zero value. On Windows, this value will always be |
| 347 | * 192 (the value of the |
| 348 | * WAIT_IO_COMPLETION constant within the Windows API). |
| 349 | * On other platforms, the return value will be the number of seconds left to |
| 350 | * sleep. |
| 351 | * @throws MiscException |
| 352 | * |
| 353 | */ |
| 354 | function sleep(int $seconds): int |
| 355 | { |
| 356 | error_clear_last(); |
| 357 | $result = \sleep($seconds); |
| 358 | if ($result === \false) { |
| 359 | throw MiscException::createFromPhpError(); |
| 360 | } |
| 361 | return $result; |
| 362 | } |
| 363 | /** |
| 364 | * Delays program execution for the given number of |
| 365 | * seconds and nanoseconds. |
| 366 | * |
| 367 | * @param int $seconds Must be a non-negative integer. |
| 368 | * @param int $nanoseconds Must be a non-negative integer less than 1 billion. |
| 369 | * @return array{0:int,1:int}|bool Returns TRUE on success. |
| 370 | * |
| 371 | * If the delay was interrupted by a signal, an associative array will be |
| 372 | * returned with the components: |
| 373 | * |
| 374 | * |
| 375 | * |
| 376 | * seconds - number of seconds remaining in |
| 377 | * the delay |
| 378 | * |
| 379 | * |
| 380 | * |
| 381 | * |
| 382 | * nanoseconds - number of nanoseconds |
| 383 | * remaining in the delay |
| 384 | * |
| 385 | * |
| 386 | * |
| 387 | * @throws MiscException |
| 388 | * |
| 389 | */ |
| 390 | function time_nanosleep(int $seconds, int $nanoseconds) |
| 391 | { |
| 392 | error_clear_last(); |
| 393 | $result = \time_nanosleep($seconds, $nanoseconds); |
| 394 | if ($result === \false) { |
| 395 | throw MiscException::createFromPhpError(); |
| 396 | } |
| 397 | return $result; |
| 398 | } |
| 399 | /** |
| 400 | * Makes the script sleep until the specified |
| 401 | * timestamp. |
| 402 | * |
| 403 | * @param float $timestamp The timestamp when the script should wake. |
| 404 | * @throws MiscException |
| 405 | * |
| 406 | */ |
| 407 | function time_sleep_until(float $timestamp): void |
| 408 | { |
| 409 | error_clear_last(); |
| 410 | $result = \time_sleep_until($timestamp); |
| 411 | if ($result === \false) { |
| 412 | throw MiscException::createFromPhpError(); |
| 413 | } |
| 414 | } |
| 415 | /** |
| 416 | * Unpacks from a binary string into an array according to the given |
| 417 | * format. |
| 418 | * |
| 419 | * The unpacked data is stored in an associative array. To |
| 420 | * accomplish this you have to name the different format codes and |
| 421 | * separate them by a slash /. If a repeater argument is present, |
| 422 | * then each of the array keys will have a sequence number behind |
| 423 | * the given name. |
| 424 | * |
| 425 | * @param string $format See pack for an explanation of the format codes. |
| 426 | * @param string $data The packed data. |
| 427 | * @param int $offset The offset to begin unpacking from. |
| 428 | * @return array Returns an associative array containing unpacked elements of binary |
| 429 | * string. |
| 430 | * @throws MiscException |
| 431 | * |
| 432 | */ |
| 433 | function unpack(string $format, string $data, int $offset = 0): array |
| 434 | { |
| 435 | error_clear_last(); |
| 436 | $result = \unpack($format, $data, $offset); |
| 437 | if ($result === \false) { |
| 438 | throw MiscException::createFromPhpError(); |
| 439 | } |
| 440 | return $result; |
| 441 | } |
| 442 |