Merge pull request #5971 from johnstevenson/xdebug-version
Set xdebug version in environment, fixes #5967pull/5979/head
commit
d735524eb1
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
namespace Composer\Repository;
|
namespace Composer\Repository;
|
||||||
|
|
||||||
|
use Composer\XdebugHandler;
|
||||||
use Composer\Package\CompletePackage;
|
use Composer\Package\CompletePackage;
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
use Composer\Package\Version\VersionParser;
|
use Composer\Package\Version\VersionParser;
|
||||||
|
@ -114,26 +115,15 @@ class PlatformRepository extends ArrayRepository
|
||||||
if (in_array($name, array('standard', 'Core'))) {
|
if (in_array($name, array('standard', 'Core'))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$extraDescription = null;
|
|
||||||
|
|
||||||
$reflExt = new \ReflectionExtension($name);
|
$reflExt = new \ReflectionExtension($name);
|
||||||
try {
|
$prettyVersion = $reflExt->getVersion();
|
||||||
$prettyVersion = $reflExt->getVersion();
|
$this->addExtension($versionParser, $name, $prettyVersion);
|
||||||
$version = $versionParser->normalize($prettyVersion);
|
}
|
||||||
} catch (\UnexpectedValueException $e) {
|
|
||||||
$extraDescription = ' (actual version: '.$prettyVersion.')';
|
|
||||||
if (preg_match('{^(\d+\.\d+\.\d+(?:\.\d+)?)}', $prettyVersion, $match)) {
|
|
||||||
$prettyVersion = $match[1];
|
|
||||||
} else {
|
|
||||||
$prettyVersion = '0';
|
|
||||||
}
|
|
||||||
$version = $versionParser->normalize($prettyVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
$packageName = $this->buildPackageName($name);
|
// Check for xdebug in a restarted process
|
||||||
$ext = new CompletePackage($packageName, $version, $prettyVersion);
|
if ($prettyVersion = strval(getenv(XdebugHandler::ENV_VERSION))) {
|
||||||
$ext->setDescription('The '.$name.' PHP extension' . $extraDescription);
|
$this->addExtension($versionParser, 'xdebug', $prettyVersion);
|
||||||
$this->addPackage($ext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Another quick loop, just for possible libraries
|
// Another quick loop, just for possible libraries
|
||||||
|
@ -255,6 +245,35 @@ class PlatformRepository extends ArrayRepository
|
||||||
parent::addPackage($package);
|
parent::addPackage($package);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the version and adds a new package to the repository
|
||||||
|
*
|
||||||
|
* @param VersionParser $versionParser
|
||||||
|
* @param string $name
|
||||||
|
* @param null|string $prettyVersion
|
||||||
|
*/
|
||||||
|
private function addExtension(VersionParser $versionParser, $name, $prettyVersion)
|
||||||
|
{
|
||||||
|
$extraDescription = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$version = $versionParser->normalize($prettyVersion);
|
||||||
|
} catch (\UnexpectedValueException $e) {
|
||||||
|
$extraDescription = ' (actual version: '.$prettyVersion.')';
|
||||||
|
if (preg_match('{^(\d+\.\d+\.\d+(?:\.\d+)?)}', $prettyVersion, $match)) {
|
||||||
|
$prettyVersion = $match[1];
|
||||||
|
} else {
|
||||||
|
$prettyVersion = '0';
|
||||||
|
}
|
||||||
|
$version = $versionParser->normalize($prettyVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
$packageName = $this->buildPackageName($name);
|
||||||
|
$ext = new CompletePackage($packageName, $version, $prettyVersion);
|
||||||
|
$ext->setDescription('The '.$name.' PHP extension'.$extraDescription);
|
||||||
|
$this->addPackage($ext);
|
||||||
|
}
|
||||||
|
|
||||||
private function buildPackageName($name)
|
private function buildPackageName($name)
|
||||||
{
|
{
|
||||||
return 'ext-' . str_replace(' ', '-', $name);
|
return 'ext-' . str_replace(' ', '-', $name);
|
||||||
|
|
|
@ -21,11 +21,13 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||||
class XdebugHandler
|
class XdebugHandler
|
||||||
{
|
{
|
||||||
const ENV_ALLOW = 'COMPOSER_ALLOW_XDEBUG';
|
const ENV_ALLOW = 'COMPOSER_ALLOW_XDEBUG';
|
||||||
|
const ENV_VERSION = 'COMPOSER_XDEBUG_VERSION';
|
||||||
const RESTART_ID = 'internal';
|
const RESTART_ID = 'internal';
|
||||||
|
|
||||||
private $output;
|
private $output;
|
||||||
private $loaded;
|
private $loaded;
|
||||||
private $envScanDir;
|
private $envScanDir;
|
||||||
|
private $version;
|
||||||
private $tmpIni;
|
private $tmpIni;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,6 +38,11 @@ class XdebugHandler
|
||||||
$this->output = $output;
|
$this->output = $output;
|
||||||
$this->loaded = extension_loaded('xdebug');
|
$this->loaded = extension_loaded('xdebug');
|
||||||
$this->envScanDir = getenv('PHP_INI_SCAN_DIR');
|
$this->envScanDir = getenv('PHP_INI_SCAN_DIR');
|
||||||
|
|
||||||
|
if ($this->loaded) {
|
||||||
|
$ext = new \ReflectionExtension('xdebug');
|
||||||
|
$this->version = strval($ext->getVersion());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -250,6 +257,11 @@ class XdebugHandler
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make xdebug version available to restarted process
|
||||||
|
if (!putenv(self::ENV_VERSION.'='.$this->version)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Flag restarted process and save env scan dir state
|
// Flag restarted process and save env scan dir state
|
||||||
$args = array(self::RESTART_ID);
|
$args = array(self::RESTART_ID);
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ class XdebugHandlerMock extends XdebugHandler
|
||||||
{
|
{
|
||||||
public $restarted;
|
public $restarted;
|
||||||
public $output;
|
public $output;
|
||||||
|
public $testVersion = '2.5.0';
|
||||||
|
|
||||||
public function __construct($loaded = null)
|
public function __construct($loaded = null)
|
||||||
{
|
{
|
||||||
|
@ -26,10 +27,16 @@ class XdebugHandlerMock extends XdebugHandler
|
||||||
|
|
||||||
$loaded = null === $loaded ? true: $loaded;
|
$loaded = null === $loaded ? true: $loaded;
|
||||||
$class = new \ReflectionClass(get_parent_class($this));
|
$class = new \ReflectionClass(get_parent_class($this));
|
||||||
|
|
||||||
$prop = $class->getProperty('loaded');
|
$prop = $class->getProperty('loaded');
|
||||||
$prop->setAccessible(true);
|
$prop->setAccessible(true);
|
||||||
$prop->setValue($this, $loaded);
|
$prop->setValue($this, $loaded);
|
||||||
|
|
||||||
|
$prop = $class->getProperty('version');
|
||||||
|
$prop->setAccessible(true);
|
||||||
|
$version = $loaded ? $this->testVersion : '';
|
||||||
|
$prop->setValue($this, $version);
|
||||||
|
|
||||||
$this->restarted = false;
|
$this->restarted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,11 +106,30 @@ class XdebugHandlerTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertEquals('', getenv('PHP_INI_SCAN_DIR'));
|
$this->assertEquals('', getenv('PHP_INI_SCAN_DIR'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEnvVersionWhenLoaded()
|
||||||
|
{
|
||||||
|
$loaded = true;
|
||||||
|
|
||||||
|
$xdebug = new XdebugHandlerMock($loaded);
|
||||||
|
$xdebug->check();
|
||||||
|
$this->assertEquals($xdebug->testVersion, getenv(XdebugHandlerMock::ENV_VERSION));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEnvVersionWhenNotLoaded()
|
||||||
|
{
|
||||||
|
$loaded = false;
|
||||||
|
|
||||||
|
$xdebug = new XdebugHandlerMock($loaded);
|
||||||
|
$xdebug->check();
|
||||||
|
$this->assertEquals(false, getenv(XdebugHandlerMock::ENV_VERSION));
|
||||||
|
}
|
||||||
|
|
||||||
public static function setUpBeforeClass()
|
public static function setUpBeforeClass()
|
||||||
{
|
{
|
||||||
// Save current state
|
// Save current state
|
||||||
$names = array(
|
$names = array(
|
||||||
XdebugHandlerMock::ENV_ALLOW,
|
XdebugHandlerMock::ENV_ALLOW,
|
||||||
|
XdebugHandlerMock::ENV_VERSION,
|
||||||
'PHP_INI_SCAN_DIR',
|
'PHP_INI_SCAN_DIR',
|
||||||
IniHelper::ENV_ORIGINAL,
|
IniHelper::ENV_ORIGINAL,
|
||||||
);
|
);
|
||||||
|
@ -136,6 +155,7 @@ class XdebugHandlerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
// Ensure env is unset
|
// Ensure env is unset
|
||||||
putenv(XdebugHandlerMock::ENV_ALLOW);
|
putenv(XdebugHandlerMock::ENV_ALLOW);
|
||||||
|
putenv(XdebugHandlerMock::ENV_VERSION);
|
||||||
putenv('PHP_INI_SCAN_DIR');
|
putenv('PHP_INI_SCAN_DIR');
|
||||||
putenv(IniHelper::ENV_ORIGINAL);
|
putenv(IniHelper::ENV_ORIGINAL);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue