Move loadPackages impl out of BaseRepository

main
Jordi Boggiano 4 years ago
parent 47a94b3a88
commit 926afab1f4
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -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}
*/

@ -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…
Cancel
Save