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 / logs / LogDebugModeResolver.php

LogDebugModeResolver.php in 404 Solution trunk, at includes/logs/LogDebugModeResolver.php

63 lines 2.3 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 * Decides whether debug logging is currently enabled.
9 *
10 * Resolution order: an in-memory PluginLogic `options['debug_mode']` override
11 * (read reflectively so an early-boot caller that has populated PluginLogic but
12 * not yet wired the options repository still gets the right answer) takes
13 * precedence; otherwise the canonical answer comes from the options repository.
14 *
15 * Pure policy: reads configuration, makes one boolean decision, writes nothing.
16 */
17 class ABJ_404_Solution_LogDebugModeResolver {
18
19 /** @return bool true if debug mode is on. false otherwise. */
20 public function isDebug(): bool {
21 $legacyDebugMode = $this->legacyPluginLogicDebugMode();
22 if ($legacyDebugMode !== null) {
23 return $legacyDebugMode;
24 }
25
26 // Raw read only via the recursion-safe logging state store. isDebug()
27 // is on the logging write path; reading via getOptions() runs the
28 // normalize pipeline, which logs on validation failure and re-enters
29 // logging -- the 4.3.0 logging<->options OOM. The store reads debug_mode
30 // with the raw, non-normalizing, non-logging accessor.
31 $store = abj_service_optional('logging_state_store');
32 if (is_object($store) && method_exists($store, 'isDebugMode')) {
33 return $store->isDebugMode();
34 }
35
36 return false;
37 }
38
39 /** @return bool|null */
40 private function legacyPluginLogicDebugMode(): ?bool {
41 if (!class_exists('ABJ_404_Solution_PluginLogic', false)) {
42 return null;
43 }
44 $pluginLogic = ABJ_404_Solution_PluginLogic::peekInstance();
45 if (!is_object($pluginLogic)) {
46 return null;
47 }
48 try {
49 $optionsProperty = new ReflectionProperty('ABJ_404_Solution_PluginLogic', 'options');
50 $options = $optionsProperty->getValue($pluginLogic);
51 if (is_array($options) && array_key_exists('debug_mode', $options)) {
52 return $options['debug_mode'] == true;
53 }
54 } catch (\Throwable $e) {
55 abj404_logPhpFallback(
56 'logger-internal',
57 'could not inspect PluginLogic debug_mode override: ' . $e->getMessage()
58 );
59 }
60 return null;
61 }
62 }
63