1
0
Fork 0

Fix support for extracting stability flags in multi-constraints, fixes #4440

pull/4541/merge
Jordi Boggiano 2015-10-27 14:59:48 +00:00
parent 507415e404
commit 82349bcb2a
2 changed files with 28 additions and 7 deletions

View File

@ -144,16 +144,33 @@ class RootPackageLoader extends ArrayLoader
$stabilities = BasePackage::$stabilities; $stabilities = BasePackage::$stabilities;
$minimumStability = $stabilities[$minimumStability]; $minimumStability = $stabilities[$minimumStability];
foreach ($requires as $reqName => $reqVersion) { foreach ($requires as $reqName => $reqVersion) {
// parse explicit stability flags to the most unstable $constraints = array();
if (preg_match('{^[^@]*?@('.implode('|', array_keys($stabilities)).')$}i', $reqVersion, $match)) {
$name = strtolower($reqName);
$stability = $stabilities[VersionParser::normalizeStability($match[1])];
if (isset($stabilityFlags[$name]) && $stabilityFlags[$name] > $stability) { // extract all sub-constraints in case it is an OR/AND multi-constraint
continue; $orSplit = preg_split('{\s*\|\|?\s*}', trim($reqVersion));
foreach ($orSplit as $constraint) {
$andSplit = preg_split('{(?<!^|as|[=>< ,]) *(?<!-)[, ](?!-) *(?!,|as|$)}', $constraint);
foreach ($andSplit as $constraint) {
$constraints[] = $constraint;
} }
$stabilityFlags[$name] = $stability; }
// parse explicit stability flags to the most unstable
$match = false;
foreach ($constraints as $constraint) {
if (preg_match('{^[^@]*?@('.implode('|', array_keys($stabilities)).')$}i', $constraint, $match)) {
$name = strtolower($reqName);
$stability = $stabilities[VersionParser::normalizeStability($match[1])];
if (isset($stabilityFlags[$name]) && $stabilityFlags[$name] > $stability) {
continue;
}
$stabilityFlags[$name] = $stability;
$match = true;
}
}
if ($match) {
continue; continue;
} }

View File

@ -42,6 +42,8 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
'bar/baz' => '1.0.x-dev as 1.2.0', 'bar/baz' => '1.0.x-dev as 1.2.0',
'qux/quux' => '1.0.*@rc', 'qux/quux' => '1.0.*@rc',
'zux/complex' => '~1.0,>=1.0.2@dev', 'zux/complex' => '~1.0,>=1.0.2@dev',
'or/op' => '^2.0@dev || ^2.0@dev',
'multi/lowest-wins' => '^2.0@rc || >=3.0@dev , ~3.5@alpha',
), ),
'minimum-stability' => 'alpha', 'minimum-stability' => 'alpha',
)); ));
@ -51,6 +53,8 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
'bar/baz' => BasePackage::STABILITY_DEV, 'bar/baz' => BasePackage::STABILITY_DEV,
'qux/quux' => BasePackage::STABILITY_RC, 'qux/quux' => BasePackage::STABILITY_RC,
'zux/complex' => BasePackage::STABILITY_DEV, 'zux/complex' => BasePackage::STABILITY_DEV,
'or/op' => BasePackage::STABILITY_DEV,
'multi/lowest-wins' => BasePackage::STABILITY_DEV,
), $package->getStabilityFlags()); ), $package->getStabilityFlags());
} }