1 | <?php |
||
11 | class XdebugToggle extends Command |
||
12 | { |
||
13 | /** |
||
14 | * The complete line containing "*_extension=*xdebug*" |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $extensionLine; |
||
19 | |||
20 | /** |
||
21 | * Extension active status |
||
22 | * |
||
23 | * @var boolean |
||
24 | */ |
||
25 | protected $extensionStatus; |
||
26 | |||
27 | /** |
||
28 | * The configuration written in php.ini for XDebug |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $extensionSettings; |
||
33 | |||
34 | /** |
||
35 | * Path of the Loaded INI file |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $iniPath; |
||
40 | |||
41 | /** |
||
42 | * Debug mode active flag |
||
43 | * |
||
44 | * @var boolean |
||
45 | */ |
||
46 | protected $debug; |
||
47 | |||
48 | /** |
||
49 | * The command signature |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $signature = 'xdebug {status : "on" or "off" to enable/disable XDebug}'; |
||
54 | |||
55 | /** |
||
56 | * The command description |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $description = 'Enables or disables XDebug extension'; |
||
61 | |||
62 | /** |
||
63 | * Class constructor |
||
64 | */ |
||
65 | public function __construct() |
||
70 | |||
71 | /** |
||
72 | * initialization routines |
||
73 | */ |
||
74 | public function initialize() |
||
86 | |||
87 | /** |
||
88 | * The method that handles the command |
||
89 | */ |
||
90 | public function handle() |
||
116 | |||
117 | /** |
||
118 | * Validates the desired status argument received from console |
||
119 | * |
||
120 | * @param string $desiredStatus Should be "on" or "off" |
||
121 | * |
||
122 | * @return boolean Whether it is a valid input |
||
123 | */ |
||
124 | public function validateDesiredStatus(string $desiredStatus) |
||
138 | |||
139 | /** |
||
140 | * Gets the XDebug status and related configuration from the loaded php.ini file |
||
141 | */ |
||
142 | private function getXDebugStatus() |
||
150 | |||
151 | /** |
||
152 | * Retrieves the INI path from php.ini file |
||
153 | * |
||
154 | * @return void |
||
155 | */ |
||
156 | private function getIniPath() |
||
169 | |||
170 | /** |
||
171 | * Validates the XDebug status received |
||
172 | * |
||
173 | * @param string $desiredStatus The desired status |
||
174 | * |
||
175 | * @return boolean Whether we should continue to modify the status or not |
||
176 | */ |
||
177 | public function validateXDebugStatus(string $desiredStatus) |
||
195 | |||
196 | /** |
||
197 | * Sets the new XDebug extension status |
||
198 | * |
||
199 | * @param string $status Whether the extension should be active or not |
||
200 | * |
||
201 | * @return void |
||
202 | */ |
||
203 | private function setXDebugStatus($status) |
||
234 | |||
235 | /** |
||
236 | * Reads the extension status from PHP ini file |
||
237 | * |
||
238 | * @return void |
||
239 | */ |
||
240 | private function getExtensionStatus() |
||
267 | |||
268 | /** |
||
269 | * Reads the extension settings from PHP ini file |
||
270 | * |
||
271 | * @return void |
||
272 | */ |
||
273 | private function getExtensionSettings() |
||
280 | |||
281 | /** |
||
282 | * Restarts the services that takes the modification into effect |
||
283 | * |
||
284 | * @return void |
||
285 | */ |
||
286 | private function restartServices() |
||
304 | } |
||
305 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.