Set xdebug version in environment, fixes #5967
parent
b1156ed376
commit
3928f1f3be
|
@ -12,6 +12,7 @@
|
|||
|
||||
namespace Composer\Repository;
|
||||
|
||||
use Composer\XdebugHandler;
|
||||
use Composer\Package\CompletePackage;
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Package\Version\VersionParser;
|
||||
|
@ -114,26 +115,15 @@ class PlatformRepository extends ArrayRepository
|
|||
if (in_array($name, array('standard', 'Core'))) {
|
||||
continue;
|
||||
}
|
||||
$extraDescription = null;
|
||||
|
||||
$reflExt = new \ReflectionExtension($name);
|
||||
try {
|
||||
$prettyVersion = $reflExt->getVersion();
|
||||
$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);
|
||||
$this->addExtension($versionParser, $name, $prettyVersion);
|
||||
}
|
||||
|
||||
$packageName = $this->buildPackageName($name);
|
||||
$ext = new CompletePackage($packageName, $version, $prettyVersion);
|
||||
$ext->setDescription('The '.$name.' PHP extension' . $extraDescription);
|
||||
$this->addPackage($ext);
|
||||
// Check for xdebug in a restarted process
|
||||
if ($prettyVersion = strval(getenv(XdebugHandler::ENV_VERSION))) {
|
||||
$this->addExtension($versionParser, 'xdebug', $prettyVersion);
|
||||
}
|
||||
|
||||
// Another quick loop, just for possible libraries
|
||||
|
@ -255,6 +245,35 @@ class PlatformRepository extends ArrayRepository
|
|||
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)
|
||||
{
|
||||
return 'ext-' . str_replace(' ', '-', $name);
|
||||
|
|
|
@ -21,11 +21,13 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||
class XdebugHandler
|
||||
{
|
||||
const ENV_ALLOW = 'COMPOSER_ALLOW_XDEBUG';
|
||||
const ENV_VERSION = 'COMPOSER_XDEBUG_VERSION';
|
||||
const RESTART_ID = 'internal';
|
||||
|
||||
private $output;
|
||||
private $loaded;
|
||||
private $envScanDir;
|
||||
private $version;
|
||||
private $tmpIni;
|
||||
|
||||
/**
|
||||
|
@ -36,6 +38,11 @@ class XdebugHandler
|
|||
$this->output = $output;
|
||||
$this->loaded = extension_loaded('xdebug');
|
||||
$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;
|
||||
}
|
||||
|
||||
// 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
|
||||
$args = array(self::RESTART_ID);
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ class XdebugHandlerMock extends XdebugHandler
|
|||
{
|
||||
public $restarted;
|
||||
public $output;
|
||||
public $testVersion = '2.5.0';
|
||||
|
||||
public function __construct($loaded = null)
|
||||
{
|
||||
|
@ -26,10 +27,16 @@ class XdebugHandlerMock extends XdebugHandler
|
|||
|
||||
$loaded = null === $loaded ? true: $loaded;
|
||||
$class = new \ReflectionClass(get_parent_class($this));
|
||||
|
||||
$prop = $class->getProperty('loaded');
|
||||
$prop->setAccessible(true);
|
||||
$prop->setValue($this, $loaded);
|
||||
|
||||
$prop = $class->getProperty('version');
|
||||
$prop->setAccessible(true);
|
||||
$version = $loaded ? $this->testVersion : '';
|
||||
$prop->setValue($this, $version);
|
||||
|
||||
$this->restarted = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,11 +106,30 @@ class XdebugHandlerTest extends \PHPUnit_Framework_TestCase
|
|||
$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()
|
||||
{
|
||||
// Save current state
|
||||
$names = array(
|
||||
XdebugHandlerMock::ENV_ALLOW,
|
||||
XdebugHandlerMock::ENV_VERSION,
|
||||
'PHP_INI_SCAN_DIR',
|
||||
IniHelper::ENV_ORIGINAL,
|
||||
);
|
||||
|
@ -136,6 +155,7 @@ class XdebugHandlerTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
// Ensure env is unset
|
||||
putenv(XdebugHandlerMock::ENV_ALLOW);
|
||||
putenv(XdebugHandlerMock::ENV_VERSION);
|
||||
putenv('PHP_INI_SCAN_DIR');
|
||||
putenv(IniHelper::ENV_ORIGINAL);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue