Browse Source

Add support for new metadata-url repo attribute

Jordi Boggiano 6 years ago
parent
commit
0961e16795
1 changed files with 11 additions and 16 deletions
  1. 11 16
      src/Composer/Repository/ComposerRepository.php

+ 11 - 16
src/Composer/Repository/ComposerRepository.php

@@ -667,6 +667,17 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
             $this->hasPartialPackages = !empty($data['packages']) && is_array($data['packages']);
         }
 
+        // metadata-url indiates V2 repo protocol so it takes over from all the V1 types
+        // V2 only has lazyProviders and no ability to process anything else, plus support for async loading
+        if (!empty($data['metadata-url'])) {
+            $this->lazyProvidersUrl = $this->canonicalizeUrl($data['metadata-url']);
+            $this->providersUrl = null;
+            $this->hasProviders = false;
+            $this->hasPartialPackages = false;
+            $this->allowSslDowngrade = false;
+            unset($data['providers-url'], $data['providers'], $data['providers-includes']);
+        }
+
         if ($this->allowSslDowngrade) {
             $this->url = str_replace('https://', 'http://', $this->url);
             $this->baseUrl = str_replace('https://', 'http://', $this->baseUrl);
@@ -681,22 +692,6 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
             $this->hasProviders = true;
         }
 
-        // TODO this is for testing only, remove once packagist reports v2 protocol support
-        if (preg_match('{^https?://repo\.packagist\.org/?$}i', $this->url)) {
-            $this->repoConfig['force-lazy-providers'] = true;
-        }
-
-        // force values for packagist
-        if (preg_match('{^https?://repo\.packagist\.org/?$}i', $this->url) && !empty($this->repoConfig['force-lazy-providers'])) {
-            $this->url = 'https://repo.packagist.org';
-            $this->baseUrl = 'https://repo.packagist.org';
-            $this->lazyProvidersUrl = $this->canonicalizeUrl('https://repo.packagist.org/p/%package%.json');
-            $this->providersUrl = null;
-        } elseif (!empty($this->repoConfig['force-lazy-providers'])) {
-            $this->lazyProvidersUrl = $this->canonicalizeUrl('/p/%package%.json');
-            $this->providersUrl = null;
-        }
-
         return $this->rootData = $data;
     }