diff --git a/src/Composer/DependencyResolver/Pool.php b/src/Composer/DependencyResolver/Pool.php index c52eb67e5..2b8dec0ad 100644 --- a/src/Composer/DependencyResolver/Pool.php +++ b/src/Composer/DependencyResolver/Pool.php @@ -33,10 +33,16 @@ class Pool protected $acceptableStabilities; protected $stabilityFlags; + // TODO BC change to stable end of june? public function __construct($minimumStability = 'dev', array $stabilityFlags = array()) { $stabilities = BasePackage::$stabilities; - $this->acceptableStabilities = array_flip(array_splice($stabilities, 0, array_search($minimumStability, $stabilities) + 1)); + $this->acceptableStabilities = array(); + foreach (BasePackage::$stabilities as $stability => $value) { + if ($value <= BasePackage::$stabilities[$minimumStability]) { + $this->acceptableStabilities[$stability] = $value; + } + } $this->stabilityFlags = $stabilityFlags; } @@ -69,7 +75,7 @@ class Pool && isset($this->acceptableStabilities[$stability])) // allow if package matches the package-specific stability flag || (isset($this->stabilityFlags[$name]) - && array_search($stability, BasePackage::$stabilities) <= $this->stabilityFlags[$name] + && BasePackage::$stabilities[$stability] <= $this->stabilityFlags[$name] ) ) { $package->setId($id++); diff --git a/src/Composer/Package/BasePackage.php b/src/Composer/Package/BasePackage.php index b3d797395..299c9b17c 100644 --- a/src/Composer/Package/BasePackage.php +++ b/src/Composer/Package/BasePackage.php @@ -32,12 +32,18 @@ abstract class BasePackage implements PackageInterface 'require-dev' => array('description' => 'requires (for development)', 'method' => 'devRequires'), ); + const STABILITY_STABLE = 0; + const STABILITY_RC = 5; + const STABILITY_BETA = 10; + const STABILITY_ALPHA = 15; + const STABILITY_DEV = 20; + public static $stabilities = array( - 'stable', - 'RC', - 'beta', - 'alpha', - 'dev', + 'stable' => self::STABILITY_STABLE, + 'RC' => self::STABILITY_RC, + 'beta' => self::STABILITY_BETA, + 'alpha' => self::STABILITY_ALPHA, + 'dev' => self::STABILITY_DEV, ); protected $name; diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php index c5cf446b5..1742b5632 100644 --- a/src/Composer/Package/Loader/RootPackageLoader.php +++ b/src/Composer/Package/Loader/RootPackageLoader.php @@ -120,9 +120,9 @@ class RootPackageLoader extends ArrayLoader $stabilities = BasePackage::$stabilities; foreach ($requires as $reqName => $reqVersion) { // parse explicit stability flags - if (preg_match('{^[^,\s]*?@('.implode('|', $stabilities).')$}i', $reqVersion, $match)) { + if (preg_match('{^[^,\s]*?@('.implode('|', array_keys($stabilities)).')$}i', $reqVersion, $match)) { $name = strtolower($reqName); - $stability = array_search(VersionParser::normalizeStability($match[1]), $stabilities); + $stability = $stabilities[VersionParser::normalizeStability($match[1])]; if (isset($stabilityFlags[$name]) && $stabilityFlags[$name] > $stability) { continue; @@ -135,7 +135,7 @@ class RootPackageLoader extends ArrayLoader // infer flags for requirements that have an explicit -dev or -beta version specified for example if (preg_match('{^[^,\s@]+$}', $reqVersion) && 'stable' !== ($stabilityName = VersionParser::parseStability($reqVersion))) { $name = strtolower($reqName); - $stability = array_search($stabilityName, $stabilities); + $stability = $stabilities[$stabilityName]; if (isset($stabilityFlags[$name]) && $stabilityFlags[$name] > $stability) { continue; } diff --git a/src/Composer/Package/MemoryPackage.php b/src/Composer/Package/MemoryPackage.php index a75c69dc5..dcb973a5b 100644 --- a/src/Composer/Package/MemoryPackage.php +++ b/src/Composer/Package/MemoryPackage.php @@ -48,6 +48,7 @@ class MemoryPackage extends BasePackage protected $prettyAlias; protected $dev; + // TODO BC change dev to stable end of june? protected $minimumStability = 'dev'; protected $stabilityFlags = array(); diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php index e7a510769..eedd5f3ae 100644 --- a/src/Composer/Package/Version/VersionParser.php +++ b/src/Composer/Package/Version/VersionParser.php @@ -151,7 +151,7 @@ class VersionParser */ public function parseConstraints($constraints) { - if (preg_match('{^([^,\s]*?)@('.implode('|', BasePackage::$stabilities).')$}i', $constraints, $match)) { + if (preg_match('{^([^,\s]*?)@('.implode('|', array_keys(BasePackage::$stabilities)).')$}i', $constraints, $match)) { $constraints = empty($match[1]) ? '*' : $match[1]; } diff --git a/tests/Composer/Test/DependencyResolver/PoolTest.php b/tests/Composer/Test/DependencyResolver/PoolTest.php index c98570534..7c6618582 100644 --- a/tests/Composer/Test/DependencyResolver/PoolTest.php +++ b/tests/Composer/Test/DependencyResolver/PoolTest.php @@ -14,6 +14,7 @@ namespace Composer\Test\DependencyResolver; use Composer\DependencyResolver\Pool; use Composer\Repository\ArrayRepository; +use Composer\Package\BasePackage; use Composer\Test\TestCase; class PoolTest extends TestCase @@ -31,6 +32,22 @@ class PoolTest extends TestCase $this->assertEquals(array($package), $pool->whatProvides('foo')); } + public function testPoolIgnoresIrrelevantPackages() + { + $pool = new Pool('stable', array('bar' => BasePackage::STABILITY_BETA)); + $repo = new ArrayRepository; + $repo->addPackage($package = $this->getPackage('bar', '1')); + $repo->addPackage($betaPackage = $this->getPackage('bar', '1-beta')); + $repo->addPackage($alphaPackage = $this->getPackage('bar', '1-alpha')); + $repo->addPackage($package2 = $this->getPackage('foo', '1')); + $repo->addPackage($rcPackage2 = $this->getPackage('foo', '1rc')); + + $pool->addRepository($repo); + + $this->assertEquals(array($package, $betaPackage), $pool->whatProvides('bar')); + $this->assertEquals(array($package2), $pool->whatProvides('foo')); + } + /** * @expectedException \RuntimeException */