XdebugHandler
in package
Tags
Table of Contents
Constants
- DEBUG = 'XDEBUG_HANDLER_DEBUG'
- RESTART_ID = 'internal'
- RESTART_SETTINGS = 'XDEBUG_HANDLER_SETTINGS'
- SUFFIX_ALLOW = '_ALLOW_XDEBUG'
- SUFFIX_INIS = '_ORIGINAL_INIS'
Properties
- $tmpIni : string|null
- $cli : bool
- $debug : string|null
- $envAllowXdebug : string
- $envOriginalInis : string
- $inRestart : bool
- $name : string
- $persistent : bool
- $script : string|null
- $skipped : string|null
- $statusWriter : Status
- $xdebugActive : bool
- $xdebugMode : string|null
- $xdebugVersion : string|null
Methods
- __construct() : mixed
- Constructor
- check() : void
- Checks if Xdebug is loaded and the process needs to be restarted
- getAllIniFiles() : array<int, string>
- Returns an array of php.ini locations with at least one entry
- getRestartSettings() : array<string|int, mixed>|null
- Returns an array of restart settings or null
- getSkippedVersion() : string
- Returns the Xdebug version that triggered a successful restart
- isXdebugActive() : bool
- Returns whether Xdebug is loaded and active
- setLogger() : self
- Activates status message output to a PSR3 logger
- setMainScript() : self
- Sets the main script location if it cannot be called from argv
- setPersistent() : self
- Persist the settings to keep Xdebug out of sub-processes
- requiresRestart() : bool
- Allows an extending class to decide if there should be a restart
- restart() : void
- Allows an extending class to access the tmpIni
- checkConfiguration() : bool
- Returns true if there are no known configuration issues
- checkMainScript() : bool
- Returns true if the script name can be used
- checkServerArgv() : array<int, string>|null
- Returns $_SERVER['argv'] if it is as expected
- doRestart() : void
- Executes the restarted command then deletes the tmp ini
- getCommand() : array<int, string>
- Returns the command line arguments for the restart
- mergeLoadedConfig() : string
- Returns default, changed and command-line ini settings
- notify() : void
- Logs status messages
- prepareRestart() : array<int, string>|null
- Returns the command line array if everything was written for the restart
- setEnvironment() : bool
- Returns true if the restart environment variables were set
- setEnvRestartSettings() : void
- Adds restart settings to the environment
- setXdebugDetails() : void
- Sets static properties $xdebugActive, $xdebugVersion and $xdebugMode
- syncSettings() : void
- Syncs settings and the environment if called with existing settings
- tryEnableSignals() : void
- Enables async signals and control interrupts in the restarted process
- writeTmpIni() : bool
- Returns true if the tmp ini file was written
Constants
DEBUG
public
mixed
DEBUG
= 'XDEBUG_HANDLER_DEBUG'
RESTART_ID
public
mixed
RESTART_ID
= 'internal'
RESTART_SETTINGS
public
mixed
RESTART_SETTINGS
= 'XDEBUG_HANDLER_SETTINGS'
SUFFIX_ALLOW
public
mixed
SUFFIX_ALLOW
= '_ALLOW_XDEBUG'
SUFFIX_INIS
public
mixed
SUFFIX_INIS
= '_ORIGINAL_INIS'
Properties
$tmpIni
protected
string|null
$tmpIni
$cli
private
bool
$cli
$debug
private
string|null
$debug
$envAllowXdebug
private
string
$envAllowXdebug
$envOriginalInis
private
string
$envOriginalInis
$inRestart
private
static bool
$inRestart
$name
private
static string
$name
$persistent
private
bool
$persistent
$script
private
string|null
$script
$skipped
private
static string|null
$skipped
$statusWriter
private
Status
$statusWriter
$xdebugActive
private
static bool
$xdebugActive
$xdebugMode
private
static string|null
$xdebugMode
$xdebugVersion
private
static string|null
$xdebugVersion
Methods
__construct()
Constructor
public
__construct(string $envPrefix) : mixed
The $envPrefix is used to create distinct environment variables. It is uppercased and prepended to the default base values. For example 'myapp' would result in MYAPP_ALLOW_XDEBUG and MYAPP_ORIGINAL_INIS.
Parameters
- $envPrefix : string
-
Value used in environment variables
Tags
check()
Checks if Xdebug is loaded and the process needs to be restarted
public
check() : void
This behaviour can be disabled by setting the MYAPP_ALLOW_XDEBUG environment variable to 1. This variable is used internally so that the restarted process is created only once.
getAllIniFiles()
Returns an array of php.ini locations with at least one entry
public
static getAllIniFiles() : array<int, string>
The equivalent of calling php_ini_loaded_file then php_ini_scanned_files. The loaded ini location is the first entry and may be an empty string.
Return values
array<int, string>getRestartSettings()
Returns an array of restart settings or null
public
static getRestartSettings() : array<string|int, mixed>|null
Settings will be available if the current process was restarted, or called with the settings from an existing restart.
Tags
Return values
array<string|int, mixed>|nullgetSkippedVersion()
Returns the Xdebug version that triggered a successful restart
public
static getSkippedVersion() : string
Return values
stringisXdebugActive()
Returns whether Xdebug is loaded and active
public
static isXdebugActive() : bool
true: if Xdebug is loaded and is running in an active mode. false: if Xdebug is not loaded, or it is running with xdebug.mode=off.
Return values
boolsetLogger()
Activates status message output to a PSR3 logger
public
setLogger(LoggerInterface $logger) : self
Parameters
- $logger : LoggerInterface
Return values
selfsetMainScript()
Sets the main script location if it cannot be called from argv
public
setMainScript(string $script) : self
Parameters
- $script : string
Return values
selfsetPersistent()
Persist the settings to keep Xdebug out of sub-processes
public
setPersistent() : self
Return values
selfrequiresRestart()
Allows an extending class to decide if there should be a restart
protected
requiresRestart(bool $default) : bool
The default is to restart if Xdebug is loaded and its mode is not "off".
Parameters
- $default : bool
Return values
boolrestart()
Allows an extending class to access the tmpIni
protected
restart(array<int, string> $command) : void
Parameters
- $command : array<int, string>
checkConfiguration()
Returns true if there are no known configuration issues
private
checkConfiguration(string|null &$info) : bool
Parameters
- $info : string|null
Return values
boolcheckMainScript()
Returns true if the script name can be used
private
checkMainScript(string &$mainScript, array<int, string> $argv) : bool
Parameters
- $mainScript : string
- $argv : array<int, string>
Return values
boolcheckServerArgv()
Returns $_SERVER['argv'] if it is as expected
private
checkServerArgv() : array<int, string>|null
Return values
array<int, string>|nulldoRestart()
Executes the restarted command then deletes the tmp ini
private
doRestart(array<int, string> $command) : void
Parameters
- $command : array<int, string>
Tags
getCommand()
Returns the command line arguments for the restart
private
getCommand(array<int, string> $argv, string $tmpIni, string $mainScript) : array<int, string>
Parameters
- $argv : array<int, string>
- $tmpIni : string
- $mainScript : string
Return values
array<int, string>mergeLoadedConfig()
Returns default, changed and command-line ini settings
private
mergeLoadedConfig(array<string|int, mixed> $loadedConfig, array<string|int, mixed> $iniConfig) : string
Parameters
- $loadedConfig : array<string|int, mixed>
-
All current ini settings
- $iniConfig : array<string|int, mixed>
-
Settings from user ini files
Return values
stringnotify()
Logs status messages
private
notify(string $op[, string|null $data = null ]) : void
Parameters
- $op : string
- $data : string|null = null
prepareRestart()
Returns the command line array if everything was written for the restart
private
prepareRestart() : array<int, string>|null
If any of the following fails (however unlikely) we must return false to stop potential recursion:
- tmp ini file creation
- environment variable creation
Return values
array<int, string>|nullsetEnvironment()
Returns true if the restart environment variables were set
private
setEnvironment(bool $scannedInis, array<int, string> $iniFiles, string $tmpIni) : bool
No need to update $_SERVER since this is set in the restarted process.
Parameters
- $scannedInis : bool
- $iniFiles : array<int, string>
-
All ini files used in the current process
- $tmpIni : string
Return values
boolsetEnvRestartSettings()
Adds restart settings to the environment
private
setEnvRestartSettings(array<int, string> $envArgs) : void
Parameters
- $envArgs : array<int, string>
setXdebugDetails()
Sets static properties $xdebugActive, $xdebugVersion and $xdebugMode
private
static setXdebugDetails() : void
syncSettings()
Syncs settings and the environment if called with existing settings
private
syncSettings(array<string|int, mixed> $settings) : void
Parameters
- $settings : array<string|int, mixed>
Tags
tryEnableSignals()
Enables async signals and control interrupts in the restarted process
private
tryEnableSignals() : void
Available on Unix PHP 7.1+ with the pcntl extension and Windows PHP 7.4+.
writeTmpIni()
Returns true if the tmp ini file was written
private
writeTmpIni(string $tmpFile, array<int, string> $iniFiles, string|null &$error) : bool
Parameters
- $tmpFile : string
- $iniFiles : array<int, string>
-
All ini files used in the current process
- $error : string|null