| 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 |
|