PluginProbe
404 Solution / trunk
404 Solution vtrunk
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / core / OpcacheAdapter.php

OpcacheAdapter.php in 404 Solution trunk, at includes/core/OpcacheAdapter.php

49 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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