Browse Source

Fix findPackage(s) implementation

Jordi Boggiano 6 years ago
parent
commit
655a784fac
1 changed files with 13 additions and 4 deletions
  1. 13 4
      src/Composer/Repository/ComposerRepository.php

+ 13 - 4
src/Composer/Repository/ComposerRepository.php

@@ -127,15 +127,24 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
      */
     public function findPackage($name, $constraint)
     {
-        if (!$this->hasProviders()) {
-            return parent::findPackage($name, $constraint);
-        }
+        // this call initializes loadRootServerFile which is needed for the rest below to work
+        $hasProviders = $this->hasProviders();
 
         $name = strtolower($name);
         if (!$constraint instanceof ConstraintInterface) {
             $constraint = $this->versionParser->parseConstraints($constraint);
         }
 
+        // TODO we need a new way for the repo to report this v2 protocol somehow
+        if ($this->lazyProvidersUrl) {
+            return $this->loadAsyncPackages(array($name => $constraint), function ($name, $stability) {
+                return true;
+            });
+        }
+        if (!$hasProviders) {
+            return parent::findPackage($name, $constraint);
+        }
+
         foreach ($this->getProviderNames() as $providerName) {
             if ($name === $providerName) {
                 $packages = $this->whatProvides($providerName);
@@ -162,7 +171,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
 
         // 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 $this->loadAsyncPackages(array($name => $constraint ?: new EmptyConstraint()), function ($name, $stability) {
                 return true;
             });
         }