Skip to content
Snippets Groups Projects
Commit 36193867 authored by David Prévot's avatar David Prévot
Browse files

New upstream version 3.0.3

parents 4642872b ced29968
No related branches found
No related tags found
No related merge requests found
name: Continuous Integration
on:
- push
- pull_request
push:
paths-ignore: ["**.md"]
pull_request:
paths-ignore: ["**.md"]
env:
COMPOSER_FLAGS: --ansi --no-interaction --no-progress --prefer-dist
......
name: PHP Lint
on:
- push
- pull_request
push:
paths-ignore: ["**.md"]
pull_request:
paths-ignore: ["**.md"]
jobs:
tests:
......
name: PHPStan
on:
- push
- pull_request
push:
paths-ignore: ["**.md"]
pull_request:
paths-ignore: ["**.md"]
env:
COMPOSER_FLAGS: --ansi --no-interaction --no-progress --prefer-dist
......
## [Unreleased]
## [3.0.3] - 2022-02-25
* Added: support for composer/pcre versions 2 and 3.
## [3.0.2] - 2022-02-24
* Fixed: regression in 3.0.1 affecting Xdebug 2
## [3.0.1] - 2022-01-04
* Fixed: error when calling `isXdebugActive` before class instantiation.
## [3.0.0] - 2021-12-23
* Removed: support for legacy PHP versions (< PHP 7.2.5).
* Added: type declarations to arguments and return values.
......@@ -99,7 +108,10 @@
* Break: the following class was renamed:
- `Composer\XdebugHandler` -> `Composer\XdebugHandler\XdebugHandler`
[Unreleased]: https://github.com/composer/xdebug-handler/compare/3.0.0...HEAD
[Unreleased]: https://github.com/composer/xdebug-handler/compare/3.0.3...HEAD
[3.0.2]: https://github.com/composer/xdebug-handler/compare/3.0.2...3.0.3
[3.0.2]: https://github.com/composer/xdebug-handler/compare/3.0.1...3.0.2
[3.0.1]: https://github.com/composer/xdebug-handler/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/composer/xdebug-handler/compare/2.0.3...3.0.0
[2.0.3]: https://github.com/composer/xdebug-handler/compare/2.0.2...2.0.3
[2.0.2]: https://github.com/composer/xdebug-handler/compare/2.0.1...2.0.2
......
# composer/xdebug-handler
[![packagist](https://img.shields.io/packagist/v/composer/xdebug-handler.svg)](https://packagist.org/packages/composer/xdebug-handler)
[![Continuous Integration](https://github.com/composer/xdebug-handler/workflows/Continuous%20Integration/badge.svg?branch=main)](https://github.com/composer/xdebug-handler/actions)
[![packagist](https://img.shields.io/packagist/v/composer/xdebug-handler)](https://packagist.org/packages/composer/xdebug-handler)
[![Continuous Integration](https://github.com/composer/xdebug-handler/actions/workflows/continuous-integration.yml/badge.svg?branch=main)](https://github.com/composer/xdebug-handler/actions?query=branch:main)
![license](https://img.shields.io/github/license/composer/xdebug-handler.svg)
![php](https://img.shields.io/packagist/php-v/composer/xdebug-handler.svg?colorB=8892BF&label=php)
![php](https://img.shields.io/packagist/php-v/composer/xdebug-handler?colorB=8892BF)
Restart a CLI process without loading the Xdebug extension, unless `xdebug.mode=off`.
......
......@@ -20,7 +20,7 @@
"require": {
"php": "^7.2.5 || ^8.0",
"psr/log": "^1 || ^2 || ^3",
"composer/pcre": "^1"
"composer/pcre": "^1 || ^2 || ^3"
},
"require-dev": {
"symfony/phpunit-bridge": "^6.0",
......
......@@ -44,6 +44,12 @@ class XdebugHandler
/** @var bool */
private static $xdebugActive;
/** @var string|null */
private static $xdebugMode;
/** @var string|null */
private static $xdebugVersion;
/** @var bool */
private $cli;
......@@ -56,12 +62,6 @@ class XdebugHandler
/** @var string */
private $envOriginalInis;
/** @var string|null */
private $loaded;
/** @var string|null */
private $mode;
/** @var bool */
private $persistent;
......@@ -91,13 +91,7 @@ class XdebugHandler
$this->envAllowXdebug = self::$name.self::SUFFIX_ALLOW;
$this->envOriginalInis = self::$name.self::SUFFIX_INIS;
if (extension_loaded('xdebug')) {
$version = phpversion('xdebug');
$this->loaded = $version !== false ? $version : 'unknown';
$this->mode = $this->getXdebugMode($this->loaded);
}
self::$xdebugActive = $this->loaded !== null && $this->mode !== 'off';
self::setXdebugDetails();
self::$inRestart = false;
if ($this->cli = PHP_SAPI === 'cli') {
......@@ -143,7 +137,7 @@ class XdebugHandler
*/
public function check(): void
{
$this->notify(Status::CHECK, $this->loaded.'|'.$this->mode);
$this->notify(Status::CHECK, self::$xdebugVersion.'|'.self::$xdebugMode);
$envArgs = explode('|', (string) getenv($this->envAllowXdebug));
if (!((bool) $envArgs[0]) && $this->requiresRestart(self::$xdebugActive)) {
......@@ -164,7 +158,7 @@ class XdebugHandler
Process::setEnv($this->envAllowXdebug);
self::$inRestart = true;
if ($this->loaded === null) {
if (self::$xdebugVersion === null) {
// Skipped version is only set if Xdebug is not loaded
self::$skipped = $envArgs[1];
}
......@@ -256,6 +250,7 @@ class XdebugHandler
*/
public static function isXdebugActive(): bool
{
self::setXdebugDetails();
return self::$xdebugActive;
}
......@@ -453,7 +448,7 @@ class XdebugHandler
// Flag restarted process and save values for it to use
$envArgs = [
self::RESTART_ID,
$this->loaded,
self::$xdebugVersion,
(int) $scannedInis,
false === $scanDir ? '*' : $scanDir,
false === $phprc ? '*' : $phprc,
......@@ -625,34 +620,49 @@ class XdebugHandler
}
/**
* Returns the Xdebug mode if available
* Sets static properties $xdebugActive, $xdebugVersion and $xdebugMode
*/
private function getXdebugMode(string $version): ?string
private static function setXdebugDetails(): void
{
if (version_compare($version, '3.1', '>=')) {
if (self::$xdebugActive !== null) {
return;
}
self::$xdebugActive = false;
if (!extension_loaded('xdebug')) {
return;
}
$version = phpversion('xdebug');
self::$xdebugVersion = $version !== false ? $version : 'unknown';
if (version_compare(self::$xdebugVersion, '3.1', '>=')) {
$modes = xdebug_info('mode');
return count($modes) === 0 ? 'off' : implode(',', $modes);
self::$xdebugMode = count($modes) === 0 ? 'off' : implode(',', $modes);
self::$xdebugActive = self::$xdebugMode !== 'off';
return;
}
// See if xdebug.mode is supported in this version
$iniMode = ini_get('xdebug.mode');
if ($iniMode === false) {
return null;
self::$xdebugActive = true;
return;
}
// Environment value wins but cannot be empty
$envMode = (string) getenv('XDEBUG_MODE');
if ($envMode !== '') {
$mode = $envMode;
self::$xdebugMode = $envMode;
} else {
$mode = $iniMode !== '' ? $iniMode : 'off';
self::$xdebugMode = $iniMode !== '' ? $iniMode : 'off';
}
// An empty comma-separated list is treated as mode 'off'
if (Preg::isMatch('/^,+$/', str_replace(' ', '', $mode))) {
$mode = 'off';
if (Preg::isMatch('/^,+$/', str_replace(' ', '', self::$xdebugMode))) {
self::$xdebugMode = 'off';
}
return $mode;
self::$xdebugActive = self::$xdebugMode !== 'off';
}
}
......@@ -132,7 +132,7 @@ abstract class BaseTestCase extends TestCase
self::assertArrayHasKey(CoreMock::ORIGINAL_INIS, $_SERVER);
// Skipped version must only be reported if it was unloaded in the restart
if (!$xdebug->parentLoaded) {
if ($xdebug->parentXdebugVersion === null) {
// Mocked successful restart without Xdebug
$version = '';
} elseif ($xdebug instanceof FailMock) {
......
......@@ -37,8 +37,8 @@ class CoreMock extends XdebugHandler
/** @var bool */
public $restarted;
/** @var bool */
public $parentLoaded;
/** @var string|null */
public $parentXdebugVersion;
/** @var null|static */
protected $childProcess;
......@@ -81,7 +81,7 @@ class CoreMock extends XdebugHandler
// properties on the parent and child
$parentProcess->restarted = true;
$xdebug->restarted = true;
$xdebug->parentLoaded = $parentProcess->parentLoaded;
$xdebug->parentXdebugVersion = $parentProcess->parentXdebugVersion;
// Make the child available
$parentProcess->childProcess = $xdebug;
......@@ -105,15 +105,15 @@ class CoreMock extends XdebugHandler
parent::__construct('mock');
$this->refClass = new \ReflectionClass('Composer\XdebugHandler\XdebugHandler');
$this->parentLoaded = $loaded ? static::TEST_VERSION : null;
$this->parentXdebugVersion = $loaded ? static::TEST_VERSION : null;
// Set private loaded
$prop = $this->refClass->getProperty('loaded');
// Set private static xdebugVersion
$prop = $this->refClass->getProperty('xdebugVersion');
$prop->setAccessible(true);
$prop->setValue($this, $this->parentLoaded);
$prop->setValue($this, $this->parentXdebugVersion);
// Set private mode
$prop = $this->refClass->getProperty('mode');
// Set private static xdebugMode
$prop = $this->refClass->getProperty('xdebugMode');
$prop->setAccessible(true);
$prop->setValue($this, $mode);
......@@ -127,11 +127,6 @@ class CoreMock extends XdebugHandler
$prop->setAccessible(true);
$prop->setValue($this, null);
// Ensure static private inRestart is unset
$prop = $this->refClass->getProperty('inRestart');
$prop->setAccessible(true);
$prop->setValue($this, null);
$this->restarted = false;
}
......
......@@ -76,7 +76,7 @@ class SettingsTest extends BaseTestCase
putenv(CoreMock::ORIGINAL_INIS);
unset($_SERVER[CoreMock::ORIGINAL_INIS]);
// Mock not loaded ($inRestart and $skipped statics are unset)
// Mock not loaded (static $skipped is unset in mock constructor)
$loaded = false;
CoreMock::createAndCheck($loaded);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment