| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Capability-safe boundary for the OPcache functions. |
| 9 |
* |
| 10 |
* Split from ABJ_404_Solution_PhpRuntimeCapabilityAdapter on the same line as |
| 11 |
* ABJ_404_Solution_PcntlSignalAdapter: OPcache is an extension, so it is |
| 12 |
* present or absent as a unit, and hosts additionally gate |
| 13 |
* opcache_get_status() behind opcache.restrict_api independently of |
| 14 |
* disable_functions. That makes "can this host answer OPcache questions" its |
| 15 |
* own question rather than two more entries in a flat capability list. |
| 16 |
* |
| 17 |
* Depends on the main adapter for the availability check and never the other |
| 18 |
* way round, so the boundary classes stay acyclic. |
| 19 |
*/ |
| 20 |
final class ABJ_404_Solution_OpcacheAdapter { |
| 21 |
|
| 22 |
/** Functions this boundary owns; consumed by the disable-functions lint. */ |
| 23 |
private const OWNED_FUNCTIONS = array( |
| 24 |
'opcache_get_status', |
| 25 |
'opcache_invalidate', |
| 26 |
); |
| 27 |
|
| 28 |
/** @return array<int, string> Functions whose direct use this boundary owns. */ |
| 29 |
public static function ownedFunctions(): array { |
| 30 |
return self::OWNED_FUNCTIONS; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* The OPcache status array, or false when this host will not disclose it. |
| 35 |
* |
| 36 |
* @return array<string, mixed>|false |
| 37 |
*/ |
| 38 |
public static function status(bool $includeScripts = true) { |
| 39 |
return ABJ_404_Solution_PhpRuntimeCapabilityAdapter::isFunctionAvailable('opcache_get_status') |
| 40 |
? @opcache_get_status($includeScripts) : false; |
| 41 |
} |
| 42 |
|
| 43 |
/** Attempt to invalidate one OPcache entry. */ |
| 44 |
public static function invalidate(string $path, bool $force = false): bool { |
| 45 |
return ABJ_404_Solution_PhpRuntimeCapabilityAdapter::isFunctionAvailable('opcache_invalidate') |
| 46 |
&& @opcache_invalidate($path, $force); |
| 47 |
} |
| 48 |
} |
| 49 |
|