diff --git a/res/composer-schema.json b/res/composer-schema.json index f1f7ed1f9..35377faff 100644 --- a/res/composer-schema.json +++ b/res/composer-schema.json @@ -143,6 +143,10 @@ "description": "A set of additional repositories where packages can be found.", "additionalProperties": true }, + "minimum-stability": { + "type": ["string"], + "description": "The minimum stability the packages must have to be install-able. Possible values are: dev, alpha, beta, RC, stable." + }, "bin": { "type": ["array"], "description": "A set of files that should be treated as binaries and symlinked into bin-dir (from config).", diff --git a/src/Composer/DependencyResolver/Pool.php b/src/Composer/DependencyResolver/Pool.php index 24ef5427a..df24a8b26 100644 --- a/src/Composer/DependencyResolver/Pool.php +++ b/src/Composer/DependencyResolver/Pool.php @@ -14,17 +14,35 @@ namespace Composer\DependencyResolver; use Composer\Package\LinkConstraint\LinkConstraintInterface; use Composer\Repository\RepositoryInterface; +use Composer\Repository\CompositeRepository; +use Composer\Repository\InstalledRepositoryInterface; +use Composer\Repository\PlatformRepository; /** * A package pool contains repositories that provide packages. * * @author Nils Adermann + * @author Jordi Boggiano */ class Pool { protected $repositories = array(); protected $packages = array(); protected $packageByName = array(); + protected $acceptableStabilities; + + public function __construct($minimumStability = 'dev') + { + $stabilities = array( + 'stable', + 'RC', + 'beta', + 'alpha', + 'dev', + ); + + $this->acceptableStabilities = array_flip(array_splice($stabilities, 0, array_search($minimumStability, $stabilities) + 1)); + } /** * Adds a repository and its packages to this package pool @@ -33,14 +51,27 @@ class Pool */ public function addRepository(RepositoryInterface $repo) { - $this->repositories[] = $repo; + if ($repo instanceof CompositeRepository) { + $repos = $repo->getRepositories(); + } else { + $repos = array($repo); + } - foreach ($repo->getPackages() as $package) { - $package->setId(count($this->packages) + 1); - $this->packages[] = $package; + foreach ($repos as $repo) { + $this->repositories[] = $repo; - foreach ($package->getNames() as $name) { - $this->packageByName[$name][] = $package; + $exempt = $repo instanceof PlatformRepository || $repo instanceof InstalledRepositoryInterface; + foreach ($repo->getPackages() as $package) { + if (!$exempt && !isset($this->acceptableStabilities[$package->getStability()])) { + continue; + } + + $package->setId(count($this->packages) + 1); + $this->packages[] = $package; + + foreach ($package->getNames() as $name) { + $this->packageByName[$name][] = $package; + } } } } diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 2f7a3b137..097c70529 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -207,7 +207,7 @@ class Installer } // creating repository pool - $pool = new Pool; + $pool = new Pool($this->package->getMinimumStability()); $pool->addRepository($installedRepo); foreach ($this->repositoryManager->getRepositories() as $repository) { $pool->addRepository($repository); diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php index 496463222..45c8f25e8 100644 --- a/src/Composer/Package/Loader/RootPackageLoader.php +++ b/src/Composer/Package/Loader/RootPackageLoader.php @@ -76,6 +76,10 @@ class RootPackageLoader extends ArrayLoader $package->setAliases($aliases); } + if (isset($config['minimum-stability'])) { + $package->setMinimumStability($config['minimum-stability']); + } + if (isset($config['repositories'])) { foreach ($config['repositories'] as $index => $repo) { if (isset($repo['packagist']) && $repo['packagist'] === false) { diff --git a/src/Composer/Package/MemoryPackage.php b/src/Composer/Package/MemoryPackage.php index cc8f9ff1c..3f701cd31 100644 --- a/src/Composer/Package/MemoryPackage.php +++ b/src/Composer/Package/MemoryPackage.php @@ -48,6 +48,8 @@ class MemoryPackage extends BasePackage protected $prettyAlias; protected $dev; + protected $minimumStability = 'dev'; + protected $requires = array(); protected $conflicts = array(); protected $provides = array(); @@ -597,6 +599,24 @@ class MemoryPackage extends BasePackage return $this->homepage; } + /** + * Set the minimumStability + * + * @param string $minimumStability + */ + public function setMinimumStability($minimumStability) + { + $this->minimumStability = $minimumStability; + } + + /** + * {@inheritDoc} + */ + public function getMinimumStability() + { + return $this->minimumStability; + } + /** * Set the autoload mapping *