PluginProbe
404 Solution / 4.3.0
404 Solution v4.3.0
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 4.3.0, at includes/logs/LogDebugModeResolver.php

55 lines 1.9 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 $options = abj_service('options_repository')->getOptions(true);
27
28 return (array_key_exists('debug_mode', $options) && $options['debug_mode'] == true);
29 }
30
31 /** @return bool|null */
32 private function legacyPluginLogicDebugMode(): ?bool {
33 if (!class_exists('ABJ_404_Solution_PluginLogic', false)) {
34 return null;
35 }
36 $pluginLogic = ABJ_404_Solution_PluginLogic::peekInstance();
37 if (!is_object($pluginLogic)) {
38 return null;
39 }
40 try {
41 $optionsProperty = new ReflectionProperty('ABJ_404_Solution_PluginLogic', 'options');
42 $options = $optionsProperty->getValue($pluginLogic);
43 if (is_array($options) && array_key_exists('debug_mode', $options)) {
44 return $options['debug_mode'] == true;
45 }
46 } catch (\Throwable $e) {
47 abj404_logPhpFallback(
48 'logger-internal',
49 'could not inspect PluginLogic debug_mode override: ' . $e->getMessage()
50 );
51 }
52 return null;
53 }
54 }
55