From e46d26cb9b6f77d4a6d7e0ae8ed33a529e753616 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 22 Aug 2012 17:47:05 +0200 Subject: [PATCH] Add loadAliasPackage to the StreamableRepositoryInterface and clear up responsibilities between Pool and Repositories --- src/Composer/DependencyResolver/Pool.php | 21 ++++++--------- .../Repository/ComposerRepository.php | 23 ++++++++++++++-- .../StreamableRepositoryInterface.php | 27 ++++++++++++++++++- 3 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/Composer/DependencyResolver/Pool.php b/src/Composer/DependencyResolver/Pool.php index 11e7184a7..f14607452 100644 --- a/src/Composer/DependencyResolver/Pool.php +++ b/src/Composer/DependencyResolver/Pool.php @@ -44,13 +44,11 @@ class Pool protected $packageByName = array(); protected $acceptableStabilities; protected $stabilityFlags; - protected $loader; protected $versionParser; public function __construct($minimumStability = 'stable', array $stabilityFlags = array()) { $stabilities = BasePackage::$stabilities; - $this->loader = new ArrayLoader; $this->versionParser = new VersionParser; $this->acceptableStabilities = array(); foreach (BasePackage::$stabilities as $stability => $value) { @@ -313,19 +311,15 @@ class Pool { if (is_array($data)) { if (isset($data['alias_of'])) { - // TODO move to $repo->loadAliasPackage? $aliasOf = $this->packageById($data['alias_of']); - $rootAlias = !empty($data['root_alias']); - $package = $this->packages[$data['id'] - 1] = new AliasPackage($aliasOf, $data['version'], $data['alias']); - $package->setId($data['id']); - $package->setRootPackageAlias($rootAlias); - - return $package; + $package = $this->packages[$data['id'] - 1] = $data['repo']->loadAliasPackage($data, $aliasOf); + $package->setRootPackageAlias(!empty($data['root_alias'])); + } else { + $package = $this->packages[$data['id'] - 1] = $data['repo']->loadPackage($data); } - $package = $this->packages[$data['id'] - 1] = $data['repo']->loadPackage($data, $data['id']); - - return $package; + $package->setId($data['id']); + $data = $package; } return $data; @@ -342,6 +336,7 @@ class Pool */ private function match($candidate, $name, LinkConstraintInterface $constraint) { + // handle array packages if (is_array($candidate)) { $candidateName = $candidate['name']; $candidateVersion = $candidate['version']; @@ -357,6 +352,7 @@ class Pool } } } else { + // handle object packages $candidateName = $candidate->getName(); $candidateVersion = $candidate->getVersion(); $provides = $candidate->getProvides(); @@ -381,5 +377,4 @@ class Pool return self::MATCH_NONE; } - } diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 3a3b05aeb..b8937bb33 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -81,6 +81,9 @@ class ComposerRepository extends ArrayRepository implements NotifiableRepository @file_get_contents($url, false, $context); } + /** + * {@inheritDoc} + */ public function getMinimalPackages() { if (isset($this->minimalPackages)) { @@ -119,15 +122,31 @@ class ComposerRepository extends ArrayRepository implements NotifiableRepository return $this->minimalPackages; } - public function loadPackage(array $data, $id) + /** + * {@inheritDoc} + */ + public function loadPackage(array $data) { $package = $this->loader->load($data['raw']); - $package->setId($id); $package->setRepository($this); return $package; } + /** + * {@inheritDoc} + */ + public function loadAliasPackage(array $data, PackageInterface $aliasOf) + { + $aliasPackage = $this->createAliasPackage($aliasOf, $data['version'], $data['alias']); + $aliasPackage->setRepository($this); + + return $aliasPackage; + } + + /** + * {@inheritDoc} + */ protected function initialize() { parent::initialize(); diff --git a/src/Composer/Repository/StreamableRepositoryInterface.php b/src/Composer/Repository/StreamableRepositoryInterface.php index e2b95cd78..7a1d2c6ce 100644 --- a/src/Composer/Repository/StreamableRepositoryInterface.php +++ b/src/Composer/Repository/StreamableRepositoryInterface.php @@ -12,6 +12,7 @@ namespace Composer\Repository; +use Composer\Package\AliasPackage; use Composer\Package\PackageInterface; /** @@ -22,9 +23,33 @@ interface StreamableRepositoryInterface extends RepositoryInterface /** * Return partial package data without loading them all to save on memory * + * The package array must contain the following fields: + * - name: package name (normalized/lowercased) + * - repo: reference to the repository instance + * - version: normalized version + * - replace: array of package name => version constraint, optional + * - provide: array of package name => version constraint, optional + * - alias: pretty alias that this package should be aliased to, optional + * - alias_normalized: normalized alias that this package should be aliased to, optional + * * @return array */ public function getMinimalPackages(); - public function loadPackage(array $data, $id); + /** + * Loads a package from minimal info of the package + * + * @param array $data the minimal info as was returned by getMinimalPackage + * @return PackageInterface + */ + public function loadPackage(array $data); + + /** + * Loads an alias package from minimal info of the package + * + * @param array $data the minimal info as was returned by getMinimalPackage + * @param PackageInterface $aliasOf the package which this alias is an alias of + * @return AliasPackage + */ + public function loadAliasPackage(array $data, PackageInterface $aliasOf); }