11
11
class Detector
12
12
{
13
13
private const DEBUG_ENV_NAME = 'APP_DEBUG ' ;
14
+ private const DEBUG_COOKIE_NAME = 'app-debug-mode ' ;
15
+
14
16
15
17
/** @var Enabler */
16
18
private $ enabler ;
@@ -28,6 +30,7 @@ public function getEnabler(): Enabler
28
30
public function isDebugMode (?bool $ default = false ): ?bool
29
31
{
30
32
return $ this ->isDebugModeByEnabler ()
33
+ ?? $ this ->isDebugModeByCookie ()
31
34
?? $ this ->isDebugModeByEnv ()
32
35
?? $ this ->isDebugModeByIp ()
33
36
?? $ default ;
@@ -36,16 +39,39 @@ public function isDebugMode(?bool $default = false): ?bool
36
39
/**
37
40
* Detect debug state by DobugModeEnabler helper
38
41
* Returned value:
39
- * - false (force to turn-off debug mode)
40
- * - true (force to turn-on debug mode)
41
- * - null (enabler is not activated)
42
+ * - `false` (force to turn-off debug mode)
43
+ * - `true` (force to turn-on debug mode)
44
+ * - `null` (enabler is not activated)
45
+ *
42
46
* @return bool|null
43
47
*/
44
48
public function isDebugModeByEnabler (): ?bool
45
49
{
46
50
return $ this ->enabler ->isDebug ();
47
51
}
48
52
53
+ /**
54
+ * Detect disabling debug mode by Cookie: `app-debug-mode: 0`
55
+ *
56
+ * ENV value vs. returned value:
57
+ * - `0`: `false` (force to turn-off debug mode)
58
+ * - `undefined` or any other value (includes `1`): `null`
59
+ *
60
+ * Note: This cookie allows only turn-off Debug mode.
61
+ * Using cookie to turn-on debug mode is unsecure!
62
+ *
63
+ * @return bool|null
64
+ */
65
+ public function isDebugModeByCookie (): ?bool
66
+ {
67
+ $ cookieValue = $ _COOKIE [self ::DEBUG_COOKIE_NAME ] ?? null ;
68
+ if (is_numeric ($ cookieValue ) && (int )$ cookieValue === 0 ) {
69
+ return false ;
70
+ }
71
+
72
+ return null ;
73
+ }
74
+
49
75
/**
50
76
* Detect debug state by ENV parameter
51
77
* ENV value vs. returned value:
0 commit comments