You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* PHP 5.3.2 minimum, although functionality is disabled below PHP 5.4.0. Using the latest PHP version is highly recommended.
27
+
* PHP 7.2.5 minimum, although using the latest PHP version is highly recommended.
28
28
29
29
## Basic Usage
30
30
```php
@@ -63,10 +63,10 @@ A temporary ini file is created from the loaded (and scanned) ini files, with an
63
63
* The main process exits with the exit code from the restarted process.
64
64
65
65
#### Signal handling
66
-
From PHP 7.1 with the pcntl extension loaded, asynchronous signal handling is automatically enabled. `SIGINT` is set to `SIG_IGN` in the parent
66
+
Asynchronous signal handling is automatically enabled if the pcntl extension is loaded. `SIGINT` is set to `SIG_IGN` in the parent
67
67
process and restored to `SIG_DFL` in the restarted process (if no other handler has been set).
68
68
69
-
From PHP 7.4 on Windows, `CTRL+C` and `CTRL+BREAK` handling is ignored in the parent process and automatically enabled in the restarted process.
69
+
From PHP 7.4 on Windows, `CTRL+C` and `CTRL+BREAK` handling is automatically enabled in the restarted process and ignored in the parent process.
70
70
71
71
### Limitations
72
72
There are a few things to be aware of when running inside a restarted process.
@@ -78,7 +78,7 @@ There are a few things to be aware of when running inside a restarted process.
78
78
### Helper methods
79
79
These static methods provide information from the current process, regardless of whether it has been restarted or not.
80
80
81
-
#### _getAllIniFiles()_
81
+
#### _getAllIniFiles(): array_
82
82
Returns an array of the original ini file locations. Use this instead of calling `php_ini_loaded_file` and `php_ini_scanned_files`, which will report the wrong values in a restarted process.
83
83
84
84
```php
@@ -93,7 +93,7 @@ $scannedInis = $files;
93
93
94
94
These locations are also available in the `MYAPP_ORIGINAL_INIS` environment variable. This is a path-separated string comprising the location returned from `php_ini_loaded_file`, which could be empty, followed by locations parsed from calling `php_ini_scanned_files`.
95
95
96
-
#### _getRestartSettings()_
96
+
#### _getRestartSettings(): ?array_
97
97
Returns an array of settings that can be used with PHP [sub-processes](#sub-processes), or null if the process was not restarted.
Returns the Xdebug version string that was skipped by the restart, or an empty value if there was no restart (or Xdebug is still loaded, perhaps by an extending class restarting for a reason other than removing Xdebug).
116
+
#### _getSkippedVersion(): string_
117
+
Returns the Xdebug version string that was skipped by the restart, or an empty string if there was no restart (or Xdebug is still loaded, perhaps by an extending class restarting for a reason other than removing Xdebug).
118
118
119
119
```php
120
120
use Composer\XdebugHandler\XdebugHandler;
121
121
122
122
$version = XdebugHandler::getSkippedVersion();
123
-
# $version: '2.6.0' (for example), or an empty string
123
+
# $version: '3.1.1' (for example), or an empty string
124
124
```
125
125
126
-
#### _isXdebugActive()_
126
+
#### _isXdebugActive(): bool_
127
127
Returns true if Xdebug is loaded and is running in an active mode (if it supports modes). Returns false if Xdebug is not loaded, or it is running with `xdebug.mode=off`.
128
128
129
129
### Setter methods
130
130
These methods implement a fluent interface and must be called before the main `check()` method.
131
131
132
-
#### _setLogger($logger)_
132
+
#### _setLogger(LoggerInterface $logger): self_
133
133
Enables the output of status messages to an external PSR3 logger. All messages are reported with either `DEBUG` or `WARNING` log levels. For example (showing the level and message):
134
134
135
135
```
136
+
// No restart
137
+
DEBUG Checking MYAPP_ALLOW_XDEBUG
138
+
DEBUG The Xdebug extension is loaded (3.1.1) xdebug.mode=off
139
+
DEBUG No restart (APP_ALLOW_XDEBUG=0) Allowed by xdebug.mode
140
+
136
141
// Restart overridden
137
142
DEBUG Checking MYAPP_ALLOW_XDEBUG
138
-
DEBUG The Xdebug extension is loaded (2.5.0)
143
+
DEBUG The Xdebug extension is loaded (3.1.1) xdebug.mode=coverage,debug,develop
139
144
DEBUG No restart (MYAPP_ALLOW_XDEBUG=1)
140
145
141
146
// Failed restart
142
147
DEBUG Checking MYAPP_ALLOW_XDEBUG
143
-
DEBUG The Xdebug extension is loaded (2.5.0)
148
+
DEBUG The Xdebug extension is loaded (3.1.0)
144
149
WARNING No restart (Unable to create temp ini file at: ...)
145
150
```
146
151
147
152
Status messages can also be output with `XDEBUG_HANDLER_DEBUG`. See [Troubleshooting](#troubleshooting).
148
153
149
-
#### _setMainScript($script)_
154
+
#### _setMainScript(string $script): self_
150
155
Sets the location of the main script to run in the restart. This is only needed in more esoteric use-cases, or if the `argv[0]` location is inaccessible. The script name `--` is supported for standard input.
151
156
152
-
#### _setPersistent()_
157
+
#### _setPersistent(): self_
153
158
Configures the restart using [persistent settings](#persistent-settings), so that Xdebug is not loaded in any sub-process.
154
159
155
160
Use this method if your application invokes one or more PHP sub-process and the Xdebug extension is not needed. This avoids the overhead of implementing specific [sub-process](#sub-processes) strategies.
@@ -234,13 +239,13 @@ The following environment settings can be used to troubleshoot unexpected behavi
234
239
### Extending the library
235
240
The API is defined by classes and their accessible elements that are not annotated as @internal. The main class has two protected methods that can be overridden to provide additional functionality:
236
241
237
-
#### _requiresRestart($default)_
242
+
#### _requiresRestart(bool $default): bool_
238
243
By default the process will restart if Xdebug is loaded and not running with `xdebug.mode=off`. Extending this method allows an application to decide, by returning a boolean (or equivalent) value.
239
244
It is only called if `MYAPP_ALLOW_XDEBUG` is empty, so it will not be called in the restarted process (where this variable contains internal data), or if the restart has been overridden.
240
245
241
246
Note that the [setMainScript()](#setmainscriptscript) and [setPersistent()](#setpersistent) setters can be used here, if required.
242
247
243
-
#### _restart($command)_
248
+
#### _restart(array $command): void_
244
249
An application can extend this to modify the temporary ini file, its location given in the `tmpIni` property. New settings can be safely appended to the end of the data, which is `PHP_EOL` terminated.
245
250
246
251
The `$command` parameter is an array of unescaped command-line arguments that will be used for the new process.
@@ -262,7 +267,7 @@ class MyRestarter extends XdebugHandler
262
267
{
263
268
private $required;
264
269
265
-
protected function requiresRestart($default)
270
+
protected function requiresRestart(bool $default): bool
266
271
{
267
272
if (Command::isHelp()) {
268
273
# No need to disable Xdebug for this
@@ -273,7 +278,7 @@ class MyRestarter extends XdebugHandler
0 commit comments