From 37550ce44b5c7d8f42c3528389a354af4b975d59 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 18 Jan 2019 18:49:45 +0100 Subject: [PATCH] Add support for new minified format --- .../Repository/ComposerRepository.php | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index e905f2b22..bb613497f 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -598,8 +598,6 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito $promises[] = $this->asyncFetchFile($url, $cacheKey, $lastModified) ->then(function ($response) use (&$packages, $contents, $name, $constraint, $repo, $isPackageAcceptableCallable) { - static $uniqKeys = array('version', 'version_normalized', 'source', 'dist', 'time'); - if (true === $response) { $response = $contents; } @@ -608,8 +606,38 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito return; } + $versions = $response['packages'][$name]; + + if (isset($response['minified']) && $response['minified'] === 'composer/2.0') { + // TODO extract in other method + $expanded = array(); + $expandedVersion = null; + foreach ($versions as $versionData) { + if (!$expandedVersion) { + $expandedVersion = $versionData; + $expanded[] = $expandedVersion; + continue; + } + + // add any changes from the previous version to the expanded one + foreach ($versionData as $key => $val) { + if ($val === '__unset') { + unset($expandedVersion[$key]); + } else { + $expandedVersion[$key] = $val; + } + } + + $expanded[] = $expandedVersion; + } + + $versions = $expanded; + unset($expanded, $expandedVersion, $versionData); + } + + static $uniqKeys = array('version', 'version_normalized', 'source', 'dist', 'time'); $versionsToLoad = array(); - foreach ($response['packages'][$name] as $version) { + foreach ($versions as $version) { if (isset($version['version_normalizeds'])) { foreach ($version['version_normalizeds'] as $index => $normalizedVersion) { if (!$repo->isVersionAcceptable($isPackageAcceptableCallable, $constraint, $name, $normalizedVersion)) {