From c257395a6d4de581add275ec51a4f1c420c570a1 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 31 May 2021 16:46:49 +0200 Subject: [PATCH 1/2] Add support for mirror-style placeholders for the dist url, fixes #9661 --- src/Composer/Package/Package.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Composer/Package/Package.php b/src/Composer/Package/Package.php index 9223fba93..a529e54ff 100644 --- a/src/Composer/Package/Package.php +++ b/src/Composer/Package/Package.php @@ -623,6 +623,11 @@ class Package extends BasePackage if (!$url) { return array(); } + + if ($urlType === 'dist' && false !== strpos($url, '%')) { + $url = ComposerMirror::processUrl($url, $this->name, $this->version, $ref, $type); + } + $urls = array($url); if ($mirrors) { foreach ($mirrors as $mirror) { From 93a5b27631b432d2bc3d7fc1dd5ec64b3418c1ec Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 1 Jun 2021 16:59:35 +0200 Subject: [PATCH 2/2] Add prettyVersion to URL placeholders --- src/Composer/Package/Package.php | 4 ++-- src/Composer/Util/ComposerMirror.php | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Composer/Package/Package.php b/src/Composer/Package/Package.php index a529e54ff..300c5ef03 100644 --- a/src/Composer/Package/Package.php +++ b/src/Composer/Package/Package.php @@ -625,14 +625,14 @@ class Package extends BasePackage } if ($urlType === 'dist' && false !== strpos($url, '%')) { - $url = ComposerMirror::processUrl($url, $this->name, $this->version, $ref, $type); + $url = ComposerMirror::processUrl($url, $this->name, $this->version, $ref, $type, $this->prettyVersion); } $urls = array($url); if ($mirrors) { foreach ($mirrors as $mirror) { if ($urlType === 'dist') { - $mirrorUrl = ComposerMirror::processUrl($mirror['url'], $this->name, $this->version, $ref, $type); + $mirrorUrl = ComposerMirror::processUrl($mirror['url'], $this->name, $this->version, $ref, $type, $this->prettyVersion); } elseif ($urlType === 'source' && $type === 'git') { $mirrorUrl = ComposerMirror::processGitUrl($mirror['url'], $this->name, $url, $type); } elseif ($urlType === 'source' && $type === 'hg') { diff --git a/src/Composer/Util/ComposerMirror.php b/src/Composer/Util/ComposerMirror.php index 036444d20..c73a2702c 100644 --- a/src/Composer/Util/ComposerMirror.php +++ b/src/Composer/Util/ComposerMirror.php @@ -19,18 +19,21 @@ namespace Composer\Util; */ class ComposerMirror { - public static function processUrl($mirrorUrl, $packageName, $version, $reference, $type) + public static function processUrl($mirrorUrl, $packageName, $version, $reference, $type, $prettyVersion = null) { if ($reference) { $reference = preg_match('{^([a-f0-9]*|%reference%)$}', $reference) ? $reference : md5($reference); } $version = strpos($version, '/') === false ? $version : md5($version); - return str_replace( - array('%package%', '%version%', '%reference%', '%type%'), - array($packageName, $version, $reference, $type), - $mirrorUrl - ); + $from = array('%package%', '%version%', '%reference%', '%type%'); + $to = array($packageName, $version, $reference, $type); + if (null !== $prettyVersion) { + $from[] = '%prettyVersion%'; + $to[] = $prettyVersion; + } + + return str_replace($from, $to, $mirrorUrl); } public static function processGitUrl($mirrorUrl, $packageName, $url, $type)