Implement loadPackages on Composer repositories with providers
parent
019ebee185
commit
261efe1e8e
|
@ -16,6 +16,7 @@ use Composer\Package\AliasPackage;
|
|||
use Composer\Package\BasePackage;
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Repository\AsyncRepositoryInterface;
|
||||
use Composer\Repository\ComposerRepository;
|
||||
use Composer\Repository\InstalledRepositoryInterface;
|
||||
use Composer\Repository\LockArrayRepository;
|
||||
use Composer\Repository\PlatformRepository;
|
||||
|
@ -83,9 +84,11 @@ class PoolBuilder
|
|||
}
|
||||
|
||||
if ($repository instanceof AsyncRepositoryInterface) {
|
||||
// TODO ispackageacceptablecallable in here?
|
||||
$packages = $repository->returnPackages($loadIds[$key]);
|
||||
} else {
|
||||
$packages = $repository->loadPackages($loadNames);
|
||||
// TODO should we really pass the callable into here?
|
||||
$packages = $repository->loadPackages($loadNames, $this->isPackageAcceptableCallable);
|
||||
}
|
||||
|
||||
foreach ($packages as $package) {
|
||||
|
|
|
@ -25,13 +25,13 @@ use Composer\Package\Link;
|
|||
abstract class BaseRepository implements RepositoryInterface
|
||||
{
|
||||
// TODO should this stay here? some repos need a better implementation
|
||||
public function loadPackages(array $packageNameMap)
|
||||
public function loadPackages(array $packageNameMap, $isPackageAcceptableCallable)
|
||||
{
|
||||
$packages = $this->getPackages();
|
||||
|
||||
$result = array();
|
||||
foreach ($packages as $package) {
|
||||
if (isset($packageNameMap[$package->getName()])) {
|
||||
if (isset($packageNameMap[$package->getName()]) && call_user_func($isPackageAcceptableCallable, $package->getNames(), $package->getStability())) {
|
||||
$result[] = $package;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -194,6 +194,26 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
|||
return parent::getPackages();
|
||||
}
|
||||
|
||||
public function loadPackages(array $packageNameMap, $isPackageAcceptableCallable)
|
||||
{
|
||||
if (!$this->hasProviders()) {
|
||||
// TODO build more efficient version of this
|
||||
return parent::loadPackages($packageNameMap, $isPackageAcceptableCallable);
|
||||
}
|
||||
|
||||
$packages = array();
|
||||
foreach ($packageNameMap as $name => $void) {
|
||||
$matches = array();
|
||||
foreach ($this->whatProvides($name, false, $isPackageAcceptableCallable) as $match) {
|
||||
if ($match->getName() === $name) {
|
||||
$matches[] = $match;
|
||||
}
|
||||
}
|
||||
$packages = array_merge($packages, $matches);
|
||||
}
|
||||
return $packages;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
@ -67,9 +67,10 @@ interface RepositoryInterface extends \Countable
|
|||
* Returns list of registered packages with the supplied name
|
||||
*
|
||||
* @param bool[] $packageNameMap
|
||||
* @param $isPackageAcceptableCallable
|
||||
* @return PackageInterface[]
|
||||
*/
|
||||
public function loadPackages(array $packageNameMap);
|
||||
public function loadPackages(array $packageNameMap, $isPackageAcceptableCallable);
|
||||
|
||||
/**
|
||||
* Searches the repository for packages containing the query
|
||||
|
|
Loading…
Reference in New Issue