| 1 |
<?php |
| 2 |
|
| 3 |
namespace WP_DEFENDER_VENDOR\Safe; |
| 4 |
|
| 5 |
use WP_DEFENDER_VENDOR\Safe\Exceptions\ApcException; |
| 6 |
|
| 7 |
/** |
| 8 |
* Retrieves cached information and meta-data from APC's data store. |
| 9 |
* |
| 10 |
* @param string $cache_type If cache_type is "user", |
| 11 |
* information about the user cache will be returned. |
| 12 |
* |
| 13 |
* If cache_type is "filehits", |
| 14 |
* information about which files have been served from the bytecode cache |
| 15 |
* for the current request will be returned. This feature must be enabled at |
| 16 |
* compile time using --enable-filehits. |
| 17 |
* |
| 18 |
* If an invalid or no cache_type is specified, information about |
| 19 |
* the system cache (cached files) will be returned. |
| 20 |
* @param bool $limited If limited is TRUE, the |
| 21 |
* return value will exclude the individual list of cache entries. This |
| 22 |
* is useful when trying to optimize calls for statistics gathering. |
| 23 |
* @return array Array of cached data (and meta-data) |
| 24 |
* @throws ApcException |
| 25 |
* |
| 26 |
*/ |
| 27 |
function apc_cache_info(string $cache_type = '', bool $limited = false): array |
| 28 |
{ |
| 29 |
error_clear_last(); |
| 30 |
$result = \apc_cache_info($cache_type, $limited); |
| 31 |
if ($result === false) { |
| 32 |
throw ApcException::createFromPhpError(); |
| 33 |
} |
| 34 |
return $result; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
/** |
| 39 |
* apc_cas updates an already existing integer value if the |
| 40 |
* old parameter matches the currently stored value |
| 41 |
* with the value of the new parameter. |
| 42 |
* |
| 43 |
* @param string $key The key of the value being updated. |
| 44 |
* @param int $old The old value (the value currently stored). |
| 45 |
* @param int $new The new value to update to. |
| 46 |
* @throws ApcException |
| 47 |
* |
| 48 |
*/ |
| 49 |
function apc_cas(string $key, int $old, int $new): void |
| 50 |
{ |
| 51 |
error_clear_last(); |
| 52 |
$result = \apc_cas($key, $old, $new); |
| 53 |
if ($result === false) { |
| 54 |
throw ApcException::createFromPhpError(); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
/** |
| 60 |
* Stores a file in the bytecode cache, bypassing all filters. |
| 61 |
* |
| 62 |
* @param string $filename Full or relative path to a PHP file that will be compiled and stored in |
| 63 |
* the bytecode cache. |
| 64 |
* @param bool $atomic |
| 65 |
* @return mixed Returns TRUE on success. |
| 66 |
* @throws ApcException |
| 67 |
* |
| 68 |
*/ |
| 69 |
function apc_compile_file(string $filename, bool $atomic = true) |
| 70 |
{ |
| 71 |
error_clear_last(); |
| 72 |
$result = \apc_compile_file($filename, $atomic); |
| 73 |
if ($result === false) { |
| 74 |
throw ApcException::createFromPhpError(); |
| 75 |
} |
| 76 |
return $result; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
/** |
| 81 |
* Decreases a stored integer value. |
| 82 |
* |
| 83 |
* @param string $key The key of the value being decreased. |
| 84 |
* @param int $step The step, or value to decrease. |
| 85 |
* @param bool|null $success Optionally pass the success or fail boolean value to |
| 86 |
* this referenced variable. |
| 87 |
* @return int Returns the current value of key's value on success |
| 88 |
* @throws ApcException |
| 89 |
* |
| 90 |
*/ |
| 91 |
function apc_dec(string $key, int $step = 1, ?bool &$success = null): int |
| 92 |
{ |
| 93 |
error_clear_last(); |
| 94 |
$result = \apc_dec($key, $step, $success); |
| 95 |
if ($result === false) { |
| 96 |
throw ApcException::createFromPhpError(); |
| 97 |
} |
| 98 |
return $result; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
/** |
| 103 |
* define is notoriously slow. Since the main benefit of |
| 104 |
* APC is to increase the performance of scripts/applications, this mechanism |
| 105 |
* is provided to streamline the process of mass constant definition. However, |
| 106 |
* this function does not perform as well as anticipated. |
| 107 |
* |
| 108 |
* For a better-performing solution, try the |
| 109 |
* hidef extension from PECL. |
| 110 |
* |
| 111 |
* @param string $key The key serves as the name of the constant set |
| 112 |
* being stored. This key is used to retrieve the |
| 113 |
* stored constants in apc_load_constants. |
| 114 |
* @param array $constants An associative array of constant_name => value |
| 115 |
* pairs. The constant_name must follow the normal |
| 116 |
* constant naming rules. |
| 117 |
* value must evaluate to a scalar value. |
| 118 |
* @param bool $case_sensitive The default behaviour for constants is to be declared case-sensitive; |
| 119 |
* i.e. CONSTANT and Constant |
| 120 |
* represent different values. If this parameter evaluates to FALSE the |
| 121 |
* constants will be declared as case-insensitive symbols. |
| 122 |
* @throws ApcException |
| 123 |
* |
| 124 |
*/ |
| 125 |
function apc_define_constants(string $key, array $constants, bool $case_sensitive = true): void |
| 126 |
{ |
| 127 |
error_clear_last(); |
| 128 |
$result = \apc_define_constants($key, $constants, $case_sensitive); |
| 129 |
if ($result === false) { |
| 130 |
throw ApcException::createFromPhpError(); |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
/** |
| 136 |
* Deletes the given files from the opcode cache. |
| 137 |
* |
| 138 |
* @param mixed $keys The files to be deleted. Accepts a string, |
| 139 |
* array of strings, or an APCIterator |
| 140 |
* object. |
| 141 |
* @return mixed Returns TRUE on success. |
| 142 |
* Or if keys is an array, then |
| 143 |
* an empty array is returned on success, or an array of failed files |
| 144 |
* is returned. |
| 145 |
* @throws ApcException |
| 146 |
* |
| 147 |
*/ |
| 148 |
function apc_delete_file($keys) |
| 149 |
{ |
| 150 |
error_clear_last(); |
| 151 |
$result = \apc_delete_file($keys); |
| 152 |
if ($result === false) { |
| 153 |
throw ApcException::createFromPhpError(); |
| 154 |
} |
| 155 |
return $result; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
/** |
| 160 |
* Removes a stored variable from the cache. |
| 161 |
* |
| 162 |
* @param string|string[]|\APCIterator $key The key used to store the value (with |
| 163 |
* apc_store). |
| 164 |
* @throws ApcException |
| 165 |
* |
| 166 |
*/ |
| 167 |
function apc_delete($key): void |
| 168 |
{ |
| 169 |
error_clear_last(); |
| 170 |
$result = \apc_delete($key); |
| 171 |
if ($result === false) { |
| 172 |
throw ApcException::createFromPhpError(); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
/** |
| 178 |
* Increases a stored number. |
| 179 |
* |
| 180 |
* @param string $key The key of the value being increased. |
| 181 |
* @param int $step The step, or value to increase. |
| 182 |
* @param bool|null $success Optionally pass the success or fail boolean value to |
| 183 |
* this referenced variable. |
| 184 |
* @return int Returns the current value of key's value on success |
| 185 |
* @throws ApcException |
| 186 |
* |
| 187 |
*/ |
| 188 |
function apc_inc(string $key, int $step = 1, ?bool &$success = null): int |
| 189 |
{ |
| 190 |
error_clear_last(); |
| 191 |
$result = \apc_inc($key, $step, $success); |
| 192 |
if ($result === false) { |
| 193 |
throw ApcException::createFromPhpError(); |
| 194 |
} |
| 195 |
return $result; |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
/** |
| 200 |
* Loads a set of constants from the cache. |
| 201 |
* |
| 202 |
* @param string $key The name of the constant set (that was stored with |
| 203 |
* apc_define_constants) to be retrieved. |
| 204 |
* @param bool $case_sensitive The default behaviour for constants is to be declared case-sensitive; |
| 205 |
* i.e. CONSTANT and Constant |
| 206 |
* represent different values. If this parameter evaluates to FALSE the |
| 207 |
* constants will be declared as case-insensitive symbols. |
| 208 |
* @throws ApcException |
| 209 |
* |
| 210 |
*/ |
| 211 |
function apc_load_constants(string $key, bool $case_sensitive = true): void |
| 212 |
{ |
| 213 |
error_clear_last(); |
| 214 |
$result = \apc_load_constants($key, $case_sensitive); |
| 215 |
if ($result === false) { |
| 216 |
throw ApcException::createFromPhpError(); |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
/** |
| 222 |
* Retrieves APC's Shared Memory Allocation information. |
| 223 |
* |
| 224 |
* @param bool $limited When set to FALSE (default) apc_sma_info will |
| 225 |
* return a detailed information about each segment. |
| 226 |
* @return array Array of Shared Memory Allocation data; FALSE on failure. |
| 227 |
* @throws ApcException |
| 228 |
* |
| 229 |
*/ |
| 230 |
function apc_sma_info(bool $limited = false): array |
| 231 |
{ |
| 232 |
error_clear_last(); |
| 233 |
$result = \apc_sma_info($limited); |
| 234 |
if ($result === false) { |
| 235 |
throw ApcException::createFromPhpError(); |
| 236 |
} |
| 237 |
return $result; |
| 238 |
} |
| 239 |
|