diff --git a/src/Composer/Repository/ArrayRepository.php b/src/Composer/Repository/ArrayRepository.php index c11c7fe68..42e9d50e1 100644 --- a/src/Composer/Repository/ArrayRepository.php +++ b/src/Composer/Repository/ArrayRepository.php @@ -28,8 +28,8 @@ class ArrayRepository extends BaseRepository { /** @var PackageInterface[] */ protected $packages; - - /** + + /** * @var PackageInterface[] indexed by package unique name and used to cache hasPackage calls */ protected $packageMap; @@ -41,6 +41,42 @@ class ArrayRepository extends BaseRepository } } + /** + * {@inheritDoc} + */ + public function loadPackages(array $packageMap, $isPackageAcceptableCallable) + { + $packages = $this->getPackages(); + + $result = array(); + $namesFound = array(); + foreach ($packages as $package) { + if (array_key_exists($package->getName(), $packageMap)) { + if ( + (!$packageMap[$package->getName()] || $packageMap[$package->getName()]->matches(new Constraint('==', $package->getVersion()))) + && call_user_func($isPackageAcceptableCallable, $package->getNames(), $package->getStability()) + ) { + $result[spl_object_hash($package)] = $package; + if ($package instanceof AliasPackage && !isset($result[spl_object_hash($package->getAliasOf())])) { + $result[spl_object_hash($package->getAliasOf())] = $package->getAliasOf(); + } + } + + $namesFound[$package->getName()] = true; + } + } + + foreach ($packages as $package) { + if ($package instanceof AliasPackage) { + if (isset($result[spl_object_hash($package->getAliasOf())])) { + $result[spl_object_hash($package)] = $package; + } + } + } + + return array('namesFound' => array_keys($namesFound), 'packages' => $result); + } + /** * {@inheritDoc} */ diff --git a/src/Composer/Repository/BaseRepository.php b/src/Composer/Repository/BaseRepository.php index dfd99d7c7..1274dbb43 100644 --- a/src/Composer/Repository/BaseRepository.php +++ b/src/Composer/Repository/BaseRepository.php @@ -25,40 +25,6 @@ use Composer\Package\Link; */ abstract class BaseRepository implements RepositoryInterface { - // TODO should this stay here? some repos need a better implementation - public function loadPackages(array $packageMap, $isPackageAcceptableCallable) - { - $packages = $this->getPackages(); - - $result = array(); - $namesFound = array(); - foreach ($packages as $package) { - if (array_key_exists($package->getName(), $packageMap)) { - if ( - (!$packageMap[$package->getName()] || $packageMap[$package->getName()]->matches(new Constraint('==', $package->getVersion()))) - && call_user_func($isPackageAcceptableCallable, $package->getNames(), $package->getStability()) - ) { - $result[spl_object_hash($package)] = $package; - if ($package instanceof AliasPackage && !isset($result[spl_object_hash($package->getAliasOf())])) { - $result[spl_object_hash($package->getAliasOf())] = $package->getAliasOf(); - } - } - - $namesFound[$package->getName()] = true; - } - } - - foreach ($packages as $package) { - if ($package instanceof AliasPackage) { - if (isset($result[spl_object_hash($package->getAliasOf())])) { - $result[spl_object_hash($package)] = $package; - } - } - } - - return array('namesFound' => array_keys($namesFound), 'packages' => $result); - } - /** * Returns a list of links causing the requested needle packages to be installed, as an associative array with the * dependent's name as key, and an array containing in order the PackageInterface and Link describing the relationship diff --git a/src/Composer/Repository/CompositeRepository.php b/src/Composer/Repository/CompositeRepository.php index ce57504f0..ddaa94694 100644 --- a/src/Composer/Repository/CompositeRepository.php +++ b/src/Composer/Repository/CompositeRepository.php @@ -94,6 +94,26 @@ class CompositeRepository extends BaseRepository return $packages ? call_user_func_array('array_merge', $packages) : array(); } + /** + * {@inheritDoc} + */ + public function loadPackages(array $packageMap, $isPackageAcceptableCallable) + { + $packages = array(); + $namesFound = array(); + foreach ($this->repositories as $repository) { + /* @var $repository RepositoryInterface */ + $result = $repository->findPackages($name, $constraint); + $packages[] = $result['packages']; + $namesFound[] = $result['namesFound']; + } + + return array( + 'packages' => $packages ? call_user_func_array('array_merge', $packages) : array(), + 'namesFound' => $namesFound ? array_unique(call_user_func_array('array_merge', $namesFound)) : array(), + ); + } + /** * {@inheritdoc} */