@@ -44,6 +44,12 @@ class XdebugHandler
44
44
/** @var bool */
45
45
private static $ xdebugActive ;
46
46
47
+ /** @var string|null */
48
+ private static $ xdebugMode ;
49
+
50
+ /** @var string|null */
51
+ private static $ xdebugVersion ;
52
+
47
53
/** @var bool */
48
54
private $ cli ;
49
55
@@ -56,12 +62,6 @@ class XdebugHandler
56
62
/** @var string */
57
63
private $ envOriginalInis ;
58
64
59
- /** @var string|null */
60
- private $ loaded ;
61
-
62
- /** @var string|null */
63
- private $ mode ;
64
-
65
65
/** @var bool */
66
66
private $ persistent ;
67
67
@@ -91,13 +91,7 @@ public function __construct(string $envPrefix)
91
91
$ this ->envAllowXdebug = self ::$ name .self ::SUFFIX_ALLOW ;
92
92
$ this ->envOriginalInis = self ::$ name .self ::SUFFIX_INIS ;
93
93
94
- if (extension_loaded ('xdebug ' )) {
95
- $ version = phpversion ('xdebug ' );
96
- $ this ->loaded = $ version !== false ? $ version : 'unknown ' ;
97
- $ this ->mode = $ this ->getXdebugMode ($ this ->loaded );
98
- }
99
-
100
- self ::$ xdebugActive = $ this ->loaded !== null && $ this ->mode !== 'off ' ;
94
+ self ::setXdebugDetails ();
101
95
self ::$ inRestart = false ;
102
96
103
97
if ($ this ->cli = PHP_SAPI === 'cli ' ) {
@@ -143,7 +137,7 @@ public function setPersistent(): self
143
137
*/
144
138
public function check (): void
145
139
{
146
- $ this ->notify (Status::CHECK , $ this -> loaded .'| ' .$ this -> mode );
140
+ $ this ->notify (Status::CHECK , self :: $ xdebugVersion .'| ' .self :: $ xdebugMode );
147
141
$ envArgs = explode ('| ' , (string ) getenv ($ this ->envAllowXdebug ));
148
142
149
143
if (!((bool ) $ envArgs [0 ]) && $ this ->requiresRestart (self ::$ xdebugActive )) {
@@ -164,7 +158,7 @@ public function check(): void
164
158
Process::setEnv ($ this ->envAllowXdebug );
165
159
self ::$ inRestart = true ;
166
160
167
- if ($ this -> loaded === null ) {
161
+ if (self :: $ xdebugVersion === null ) {
168
162
// Skipped version is only set if Xdebug is not loaded
169
163
self ::$ skipped = $ envArgs [1 ];
170
164
}
@@ -256,6 +250,7 @@ public static function getSkippedVersion(): string
256
250
*/
257
251
public static function isXdebugActive (): bool
258
252
{
253
+ self ::setXdebugDetails ();
259
254
return self ::$ xdebugActive ;
260
255
}
261
256
@@ -453,7 +448,7 @@ private function setEnvironment(bool $scannedInis, array $iniFiles): bool
453
448
// Flag restarted process and save values for it to use
454
449
$ envArgs = [
455
450
self ::RESTART_ID ,
456
- $ this -> loaded ,
451
+ self :: $ xdebugVersion ,
457
452
(int ) $ scannedInis ,
458
453
false === $ scanDir ? '* ' : $ scanDir ,
459
454
false === $ phprc ? '* ' : $ phprc ,
@@ -625,34 +620,48 @@ private function tryEnableSignals(): void
625
620
}
626
621
627
622
/**
628
- * Returns the Xdebug mode if available
623
+ * Sets static properties $xdebugActive, $xdebugVersion and $xdebugMode
629
624
*/
630
- private function getXdebugMode ( string $ version ): ? string
625
+ private static function setXdebugDetails ( ): void
631
626
{
632
- if (version_compare ($ version , '3.1 ' , '>= ' )) {
627
+ if (self ::$ xdebugActive !== null ) {
628
+ return ;
629
+ }
630
+
631
+ self ::$ xdebugActive = false ;
632
+ if (!extension_loaded ('xdebug ' )) {
633
+ return ;
634
+ }
635
+
636
+ $ version = phpversion ('xdebug ' );
637
+ self ::$ xdebugVersion = $ version !== false ? $ version : 'unknown ' ;
638
+
639
+ if (version_compare (self ::$ xdebugVersion , '3.1 ' , '>= ' )) {
633
640
$ modes = xdebug_info ('mode ' );
634
- return count ($ modes ) === 0 ? 'off ' : implode (', ' , $ modes );
641
+ self ::$ xdebugMode = count ($ modes ) === 0 ? 'off ' : implode (', ' , $ modes );
642
+ self ::$ xdebugActive = self ::$ xdebugMode !== 'off ' ;
643
+ return ;
635
644
}
636
645
637
646
// See if xdebug.mode is supported in this version
638
647
$ iniMode = ini_get ('xdebug.mode ' );
639
648
if ($ iniMode === false ) {
640
- return null ;
649
+ return ;
641
650
}
642
651
643
652
// Environment value wins but cannot be empty
644
653
$ envMode = (string ) getenv ('XDEBUG_MODE ' );
645
654
if ($ envMode !== '' ) {
646
- $ mode = $ envMode ;
655
+ self :: $ xdebugMode = $ envMode ;
647
656
} else {
648
- $ mode = $ iniMode !== '' ? $ iniMode : 'off ' ;
657
+ self :: $ xdebugMode = $ iniMode !== '' ? $ iniMode : 'off ' ;
649
658
}
650
659
651
660
// An empty comma-separated list is treated as mode 'off'
652
- if (Preg::isMatch ('/^,+$/ ' , str_replace (' ' , '' , $ mode ))) {
653
- $ mode = 'off ' ;
661
+ if (Preg::isMatch ('/^,+$/ ' , str_replace (' ' , '' , self :: $ xdebugMode ))) {
662
+ self :: $ xdebugMode = 'off ' ;
654
663
}
655
664
656
- return $ mode ;
665
+ self :: $ xdebugActive = self :: $ xdebugMode !== ' off ' ;
657
666
}
658
667
}
0 commit comments