From 346de47af23cbc8441bd1683491d5c25592b8a42 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 12 Nov 2018 17:21:23 +0100 Subject: [PATCH] Small fixes --- src/Composer/Command/CreateProjectCommand.php | 2 +- .../Repository/ComposerRepository.php | 25 +++++++++++++++++-- .../Repository/RepositoryInterface.php | 11 ++++---- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 1b58d59c5..a1c364539 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -374,7 +374,7 @@ EOT { $factory = new Factory(); - return $factory->createDownloadManager($io, $config); + return $factory->createDownloadManager($io, $config, $factory->createHttpDownloader($io, $config)); } protected function createInstallationManager() diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index b337ea106..7b916d95a 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -28,6 +28,7 @@ use Composer\EventDispatcher\EventDispatcher; use Composer\Downloader\TransportException; use Composer\Semver\Constraint\ConstraintInterface; use Composer\Semver\Constraint\Constraint; +use Composer\Semver\Constraint\EmptyConstraint; /** * @author Jordi Boggiano @@ -156,9 +157,19 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito */ public function findPackages($name, $constraint = null) { - if (!$this->hasProviders()) { + // this call initializes loadRootServerFile which is needed for the rest below to work + $hasProviders = $this->hasProviders(); + + // TODO we need a new way for the repo to report this v2 protocol somehow + if ($this->lazyProvidersUrl) { + return $this->loadAsyncPackages(array($name => new EmptyConstraint()), function ($name, $stability) { + return true; + }); + } + if (!$hasProviders) { return parent::findPackages($name, $constraint); } + // normalize name $name = strtolower($name); @@ -197,10 +208,14 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito public function loadPackages(array $packageNameMap, $isPackageAcceptableCallable) { + // this call initializes loadRootServerFile which is needed for the rest below to work + $hasProviders = $this->hasProviders(); + + // TODO we need a new way for the repo to report this v2 protocol somehow if ($this->lazyProvidersUrl) { return $this->loadAsyncPackages($packageNameMap, $isPackageAcceptableCallable); } - if (!$this->hasProviders()) { + if (!$hasProviders) { return parent::loadPackages($packageNameMap, $isPackageAcceptableCallable); } @@ -225,6 +240,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito } $packages = array_merge($packages, $matches); } + return $packages; } @@ -528,6 +544,11 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito if ($this->lazyProvidersUrl) { foreach ($packageNames as $name => $constraint) { + // skip platform packages, root package and composer-plugin-api + if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $name) || '__root__' === $name || 'composer-plugin-api' === $name) { + continue; + } + $url = str_replace('%package%', $name, $this->lazyProvidersUrl); $cacheKey = 'provider-'.strtr($name, '/', '$').'.json'; diff --git a/src/Composer/Repository/RepositoryInterface.php b/src/Composer/Repository/RepositoryInterface.php index 55b76d33d..567455163 100644 --- a/src/Composer/Repository/RepositoryInterface.php +++ b/src/Composer/Repository/RepositoryInterface.php @@ -13,6 +13,7 @@ namespace Composer\Repository; use Composer\Package\PackageInterface; +use Composer\Semver\Constraint\ConstraintInterface; /** * Repository interface. @@ -38,8 +39,8 @@ interface RepositoryInterface extends \Countable /** * Searches for the first match of a package by name and version. * - * @param string $name package name - * @param string|\Composer\Semver\Constraint\ConstraintInterface $constraint package version or version constraint to match against + * @param string $name package name + * @param string|ConstraintInterface $constraint package version or version constraint to match against * * @return PackageInterface|null */ @@ -48,8 +49,8 @@ interface RepositoryInterface extends \Countable /** * Searches for all packages matching a name and optionally a version. * - * @param string $name package name - * @param string|\Composer\Semver\Constraint\ConstraintInterface $constraint package version or version constraint to match against + * @param string $name package name + * @param string|ConstraintInterface $constraint package version or version constraint to match against * * @return PackageInterface[] */ @@ -66,7 +67,7 @@ interface RepositoryInterface extends \Countable /** * Returns list of registered packages with the supplied name * - * @param bool[] $packageNameMap + * @param ConstraintInterface[] $packageNameMap package names pointing to constraints * @param $isPackageAcceptableCallable * @return PackageInterface[] */