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
{{ message }}
Repository navigation
Commit 09a0a96
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: vendor/composer/xdebug-handler/README.md
+49-15Lines changed: 49 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,6 +42,8 @@ The constructor takes a single parameter, `$envPrefix`, which is upper-cased and
42
42
-`MYAPP_ALLOW_XDEBUG=1` to override automatic restart and allow Xdebug
43
43
-`MYAPP_ORIGINAL_INIS` to obtain ini file locations in a restarted process
44
44
45
+
>If the application restarts in a new PHP process, it starts from the beginning, so any code that ran before `$xdebug->check()` runs again. Call this method as early as possible to avoid repeating unnecessary work.
46
+
45
47
## Advanced Usage
46
48
47
49
*[How it works](#how-it-works)
@@ -91,13 +93,15 @@ use Composer\XdebugHandler\XdebugHandler;
91
93
92
94
$files = XdebugHandler::getAllIniFiles();
93
95
94
-
# $files[0] always exists, it could be an empty string
96
+
// $files[0] always exists, it could be an empty string
95
97
$loadedIni = array_shift($files);
96
98
$scannedInis = $files;
97
99
```
98
100
99
101
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`.
100
102
103
+
---
104
+
101
105
#### _getRestartSettings(): ?array_
102
106
Returns an array of settings that can be used with PHP [sub-processes](#sub-processes), or null if the process was not restarted.
* 'skipped' => the skipped version from getSkippedVersion (string)
118
122
*/
119
123
```
124
+
---
120
125
121
126
#### _getSkippedVersion(): string_
122
127
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).
@@ -125,8 +130,9 @@ Returns the Xdebug version string that was skipped by the restart, or an empty s
125
130
use Composer\XdebugHandler\XdebugHandler;
126
131
127
132
$version = XdebugHandler::getSkippedVersion();
128
-
# $version: '3.1.1' (for example), or an empty string
133
+
// $version: '3.1.1' (for example), or an empty string
129
134
```
135
+
---
130
136
131
137
#### _isXdebugActive(): bool_
132
138
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`.
@@ -156,9 +162,13 @@ WARNING No restart (Unable to create temp ini file at: ...)
156
162
157
163
Status messages can also be output with `XDEBUG_HANDLER_DEBUG`. See [Troubleshooting](#troubleshooting).
158
164
165
+
---
166
+
159
167
#### _setMainScript(string $script): self_
160
168
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.
161
169
170
+
---
171
+
162
172
#### _setPersistent(): self_
163
173
Configures the restart using [persistent settings](#persistent-settings), so that Xdebug is not loaded in any sub-process.
164
174
@@ -171,16 +181,17 @@ function SubProcessWithXdebug()
171
181
{
172
182
$phpConfig = new Composer\XdebugHandler\PhpConfig();
173
183
174
-
# Set the environment to the original configuration
184
+
// Set the environment to the original configuration
175
185
$phpConfig->useOriginal();
176
186
177
-
# run the process with Xdebug loaded
187
+
// Run the process with Xdebug loaded
178
188
...
179
189
180
-
# Restore Xdebug-free environment
190
+
// Restore Xdebug-free environment
181
191
$phpConfig->usePersistent();
182
192
}
183
193
```
194
+
---
184
195
185
196
### Process configuration
186
197
The library offers two strategies to invoke a new PHP process without loading Xdebug, using either _standard_ or _persistent_ settings. Note that this is only important if the application calls a PHP sub-process.
@@ -222,41 +233,55 @@ use Composer\XdebugHandler\PhpConfig;
222
233
$config = new PhpConfig;
223
234
224
235
$options = $config->useOriginal();
225
-
# $options: empty array
226
-
# environment: PHPRC and PHP_INI_SCAN_DIR set to original values
236
+
// $options: empty array
237
+
// environment: PHPRC and PHP_INI_SCAN_DIR set to original values
227
238
228
239
$options = $config->useStandard();
229
-
# $options: [-n, -c, tmpIni]
230
-
# environment: PHPRC and PHP_INI_SCAN_DIR set to original values
240
+
// $options: [-n, -c, tmpIni]
241
+
// environment: PHPRC and PHP_INI_SCAN_DIR set to original values
231
242
232
243
$options = $config->usePersistent();
233
-
# $options: empty array
234
-
# environment: PHPRC=tmpIni, PHP_INI_SCAN_DIR=''
244
+
// $options: empty array
245
+
// environment: PHPRC=tmpIni, PHP_INI_SCAN_DIR=''
235
246
```
236
247
237
248
### Troubleshooting
238
-
The following environment settings can be used to troubleshoot unexpected behavior:
249
+
The following environment settings can be used to troubleshoot unexpected behaviour:
239
250
240
251
*`XDEBUG_HANDLER_DEBUG=1` Outputs status messages to `STDERR`, if it is defined, irrespective of any PSR3 logger. Each message is prefixed `xdebug-handler[pid]`, where pid is the process identifier.
241
252
242
253
*`XDEBUG_HANDLER_DEBUG=2` As above, but additionally saves the temporary ini file and reports its location in a status message.
243
254
244
255
### Extending the library
245
-
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:
256
+
The API is defined by classes and their accessible elements that are not annotated as @internal. The main class has four protected methods, two of which can be overridden to provide additional functionality:
246
257
247
258
#### _requiresRestart(bool $default): bool_
248
259
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.
249
260
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.
250
261
251
262
Note that the [setMainScript()](#setmainscriptstring-script-self) and [setPersistent()](#setpersistent-self) setters can be used here, if required.
252
263
264
+
---
265
+
253
266
#### _restart(array $command): void_
254
267
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.
255
268
256
269
The `$command` parameter is an array of unescaped command-line arguments that will be used for the new process.
257
270
258
271
Remember to finish with `parent::restart($command)`.
259
272
273
+
---
274
+
275
+
#### _outputError(string $message): void_
276
+
Outputs an error status message. This will be logged at WARNING level and output to STDERR. See [setLogger](#setloggerloggerinterface-logger-self) and [Troubleshooting](#troubleshooting) for more information.
277
+
278
+
---
279
+
280
+
#### _outputInfo(string $message): void_
281
+
Output an informational status message. This will be logged at DEBUG level and output to STDERR. See [setLogger](#setloggerloggerinterface-logger-self) and [Troubleshooting](#troubleshooting) for more information.
282
+
283
+
---
284
+
260
285
#### Example
261
286
This example demonstrates two ways to extend basic functionality:
262
287
@@ -275,21 +300,30 @@ class MyRestarter extends XdebugHandler
275
300
protected function requiresRestart(bool $default): bool
0 commit comments