| 1 |
<?php |
| 2 |
|
| 3 |
namespace WP_DEFENDER_VENDOR\Safe; |
| 4 |
|
| 5 |
use WP_DEFENDER_VENDOR\Safe\Exceptions\SplException; |
| 6 |
|
| 7 |
/** |
| 8 |
* This function returns an array with the names of the interfaces that the |
| 9 |
* given class and its parents implement. |
| 10 |
* |
| 11 |
* @param mixed $class An object (class instance) or a string (class or interface name). |
| 12 |
* @param bool $autoload Whether to allow this function to load the class automatically through |
| 13 |
* the __autoload magic method. |
| 14 |
* @return array An array on success. |
| 15 |
* @throws SplException |
| 16 |
* |
| 17 |
*/ |
| 18 |
function class_implements($class, bool $autoload = true): array |
| 19 |
{ |
| 20 |
error_clear_last(); |
| 21 |
$result = \class_implements($class, $autoload); |
| 22 |
if ($result === false) { |
| 23 |
throw SplException::createFromPhpError(); |
| 24 |
} |
| 25 |
return $result; |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
/** |
| 30 |
* This function returns an array with the name of the parent classes of |
| 31 |
* the given class. |
| 32 |
* |
| 33 |
* @param mixed $class An object (class instance) or a string (class name). |
| 34 |
* @param bool $autoload Whether to allow this function to load the class automatically through |
| 35 |
* the __autoload magic method. |
| 36 |
* @return array An array on success. |
| 37 |
* @throws SplException |
| 38 |
* |
| 39 |
*/ |
| 40 |
function class_parents($class, bool $autoload = true): array |
| 41 |
{ |
| 42 |
error_clear_last(); |
| 43 |
$result = \class_parents($class, $autoload); |
| 44 |
if ($result === false) { |
| 45 |
throw SplException::createFromPhpError(); |
| 46 |
} |
| 47 |
return $result; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
/** |
| 52 |
* This function returns an array with the names of the traits that the |
| 53 |
* given class uses. This does however not include |
| 54 |
* any traits used by a parent class. |
| 55 |
* |
| 56 |
* @param mixed $class An object (class instance) or a string (class name). |
| 57 |
* @param bool $autoload Whether to allow this function to load the class automatically through |
| 58 |
* the __autoload magic method. |
| 59 |
* @return array An array on success. |
| 60 |
* @throws SplException |
| 61 |
* |
| 62 |
*/ |
| 63 |
function class_uses($class, bool $autoload = true): array |
| 64 |
{ |
| 65 |
error_clear_last(); |
| 66 |
$result = \class_uses($class, $autoload); |
| 67 |
if ($result === false) { |
| 68 |
throw SplException::createFromPhpError(); |
| 69 |
} |
| 70 |
return $result; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
/** |
| 75 |
* Register a function with the spl provided __autoload queue. If the queue |
| 76 |
* is not yet activated it will be activated. |
| 77 |
* |
| 78 |
* If your code has an existing __autoload function then |
| 79 |
* this function must be explicitly registered on the __autoload queue. This |
| 80 |
* is because spl_autoload_register will effectively |
| 81 |
* replace the engine cache for the __autoload function |
| 82 |
* by either spl_autoload or |
| 83 |
* spl_autoload_call. |
| 84 |
* |
| 85 |
* If there must be multiple autoload functions, spl_autoload_register |
| 86 |
* allows for this. It effectively creates a queue of autoload functions, and |
| 87 |
* runs through each of them in the order they are defined. By contrast, |
| 88 |
* __autoload may only be defined once. |
| 89 |
* |
| 90 |
* @param callable(string):void|null $autoload_function The autoload function being registered. |
| 91 |
* If no parameter is provided, then the default implementation of |
| 92 |
* spl_autoload will be registered. |
| 93 |
* @param bool $throw This parameter specifies whether |
| 94 |
* spl_autoload_register should throw |
| 95 |
* exceptions when the autoload_function |
| 96 |
* cannot be registered. |
| 97 |
* @param bool $prepend If true, spl_autoload_register will prepend |
| 98 |
* the autoloader on the autoload queue instead of appending it. |
| 99 |
* |
| 100 |
* @throws SplException |
| 101 |
* |
| 102 |
*/ |
| 103 |
function spl_autoload_register(?callable $autoload_function = null, bool $throw = true, bool $prepend = false): void |
| 104 |
{ |
| 105 |
error_clear_last(); |
| 106 |
if ($prepend !== false) { |
| 107 |
$result = \spl_autoload_register($autoload_function, $throw, $prepend); |
| 108 |
} elseif ($throw !== true) { |
| 109 |
$result = \spl_autoload_register($autoload_function, $throw); |
| 110 |
} elseif ($autoload_function !== null) { |
| 111 |
$result = \spl_autoload_register($autoload_function); |
| 112 |
} else { |
| 113 |
$result = \spl_autoload_register(); |
| 114 |
} |
| 115 |
if ($result === false) { |
| 116 |
throw SplException::createFromPhpError(); |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
/** |
| 122 |
* Removes a function from the autoload queue. If the queue |
| 123 |
* is activated and empty after removing the given function then it will |
| 124 |
* be deactivated. |
| 125 |
* |
| 126 |
* When this function results in the queue being deactivated, any |
| 127 |
* __autoload function that previously existed will not be reactivated. |
| 128 |
* |
| 129 |
* @param mixed $autoload_function The autoload function being unregistered. |
| 130 |
* @throws SplException |
| 131 |
* |
| 132 |
*/ |
| 133 |
function spl_autoload_unregister($autoload_function): void |
| 134 |
{ |
| 135 |
error_clear_last(); |
| 136 |
$result = \spl_autoload_unregister($autoload_function); |
| 137 |
if ($result === false) { |
| 138 |
throw SplException::createFromPhpError(); |
| 139 |
} |
| 140 |
} |
| 141 |
|