@@ -13,13 +13,21 @@ class Detector
13
13
private const DEBUG_ENV_NAME = 'APP_DEBUG ' ;
14
14
private const DEBUG_COOKIE_NAME = 'app-debug-mode ' ;
15
15
16
+ public const MODE_ENABLER = 0b0001 ;
17
+ public const MODE_COOKIE = 0b0010 ;
18
+ public const MODE_ENV = 0b0100 ;
19
+ public const MODE_IP = 0b1000 ;
20
+ public const MODE_ALL = self ::MODE_ENABLER | self ::MODE_COOKIE | self ::MODE_ENV | self ::MODE_IP ;
16
21
17
22
/** @var Enabler */
18
23
private $ enabler ;
24
+ /** @var int */
25
+ private $ mode ;
19
26
20
- public function __construct (string $ tempDir )
27
+ public function __construct (string $ tempDir, int $ mode = self :: MODE_ALL )
21
28
{
22
29
$ this ->enabler = new Enabler ($ tempDir );
30
+ $ this ->mode = $ mode ;
23
31
}
24
32
25
33
public function getEnabler (): Enabler
@@ -29,10 +37,10 @@ public function getEnabler(): Enabler
29
37
30
38
public function isDebugMode (?bool $ default = false ): ?bool
31
39
{
32
- return $ this ->isDebugModeByEnabler ()
33
- ?? $ this ->isDebugModeByCookie ()
34
- ?? $ this ->isDebugModeByEnv ()
35
- ?? $ this ->isDebugModeByIp ()
40
+ return ( $ this ->mode & self :: MODE_ENABLER ? $ this -> isDebugModeByEnabler () : null )
41
+ ?? ( $ this ->mode & self :: MODE_COOKIE ? $ this -> isDebugModeByCookie () : null )
42
+ ?? ( $ this ->mode & self :: MODE_ENV ? $ this -> isDebugModeByEnv () : null )
43
+ ?? ( $ this ->mode & self :: MODE_IP ? $ this -> isDebugModeByIp () : null )
36
44
?? $ default ;
37
45
}
38
46
@@ -114,9 +122,9 @@ public function isDebugModeByIp(): ?bool
114
122
return $ result ?: null ;
115
123
}
116
124
117
- public static function detect (string $ tempDir , ?bool $ default = false ): ?bool
125
+ public static function detect (string $ tempDir , int $ mode = self :: MODE_ALL , ?bool $ default = false ): ?bool
118
126
{
119
- return (new self ($ tempDir ))->isDebugMode ($ default );
127
+ return (new self ($ tempDir, $ mode ))->isDebugMode ($ default );
120
128
}
121
129
122
130
public static function detectProductionMode (string $ tempDir , ?bool $ default = false ): ?bool
0 commit comments