Move loadPackages impl out of BaseRepository
parent
47a94b3a88
commit
926afab1f4
|
@ -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}
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue