Skip to content

Commit ce991ac

Browse files
committed
Update documentation
1 parent 16057ba commit ce991ac

File tree

2 files changed

+25
-50
lines changed

2 files changed

+25
-50
lines changed

README.md

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Restart a CLI process without loading the Xdebug extension, unless `xdebug.mode=
1010
Originally written as part of [composer/composer](https://github.com/composer/composer),
1111
now extracted and made available as a stand-alone library.
1212

13-
### Version 2
13+
### Version 3
1414

15-
Support added for Xdebug3. See [UPGRADE](UPGRADE.md) for more information.
15+
Removed support for legacy PHP versions and added type declarations.
1616

1717
## Installation
1818

@@ -24,7 +24,7 @@ $ composer require composer/xdebug-handler
2424

2525
## Requirements
2626

27-
* 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.
2828

2929
## Basic Usage
3030
```php
@@ -63,10 +63,10 @@ A temporary ini file is created from the loaded (and scanned) ini files, with an
6363
* The main process exits with the exit code from the restarted process.
6464

6565
#### 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
6767
process and restored to `SIG_DFL` in the restarted process (if no other handler has been set).
6868

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.
7070

7171
### Limitations
7272
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.
7878
### Helper methods
7979
These static methods provide information from the current process, regardless of whether it has been restarted or not.
8080

81-
#### _getAllIniFiles()_
81+
#### _getAllIniFiles(): array_
8282
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.
8383

8484
```php
@@ -93,7 +93,7 @@ $scannedInis = $files;
9393

9494
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`.
9595

96-
#### _getRestartSettings()_
96+
#### _getRestartSettings(): ?array_
9797
Returns an array of settings that can be used with PHP [sub-processes](#sub-processes), or null if the process was not restarted.
9898

9999
```php
@@ -113,43 +113,48 @@ $settings = XdebugHandler::getRestartSettings();
113113
*/
114114
```
115115

116-
#### _getSkippedVersion()_
117-
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).
118118

119119
```php
120120
use Composer\XdebugHandler\XdebugHandler;
121121

122122
$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
124124
```
125125

126-
#### _isXdebugActive()_
126+
#### _isXdebugActive(): bool_
127127
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`.
128128

129129
### Setter methods
130130
These methods implement a fluent interface and must be called before the main `check()` method.
131131

132-
#### _setLogger($logger)_
132+
#### _setLogger(LoggerInterface $logger): self_
133133
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):
134134

135135
```
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+
136141
// Restart overridden
137142
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
139144
DEBUG No restart (MYAPP_ALLOW_XDEBUG=1)
140145
141146
// Failed restart
142147
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)
144149
WARNING No restart (Unable to create temp ini file at: ...)
145150
```
146151

147152
Status messages can also be output with `XDEBUG_HANDLER_DEBUG`. See [Troubleshooting](#troubleshooting).
148153

149-
#### _setMainScript($script)_
154+
#### _setMainScript(string $script): self_
150155
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.
151156

152-
#### _setPersistent()_
157+
#### _setPersistent(): self_
153158
Configures the restart using [persistent settings](#persistent-settings), so that Xdebug is not loaded in any sub-process.
154159

155160
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
234239
### Extending the library
235240
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:
236241

237-
#### _requiresRestart($default)_
242+
#### _requiresRestart(bool $default): bool_
238243
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.
239244
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.
240245

241246
Note that the [setMainScript()](#setmainscriptscript) and [setPersistent()](#setpersistent) setters can be used here, if required.
242247

243-
#### _restart($command)_
248+
#### _restart(array $command): void_
244249
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.
245250

246251
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
262267
{
263268
private $required;
264269

265-
protected function requiresRestart($default)
270+
protected function requiresRestart(bool $default): bool
266271
{
267272
if (Command::isHelp()) {
268273
# No need to disable Xdebug for this
@@ -273,7 +278,7 @@ class MyRestarter extends XdebugHandler
273278
return $this->required || $default;
274279
}
275280

276-
protected function restart($command)
281+
protected function restart(array $command): void
277282
{
278283
if ($this->required) {
279284
# Add required ini setting to tmpIni

UPGRADE.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)