1
0
Fork 0

Add prettyVersion to URL placeholders

pull/9925/head
Jordi Boggiano 2021-06-01 16:59:35 +02:00
parent c257395a6d
commit 93a5b27631
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 11 additions and 8 deletions

View File

@ -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') {

View File

@ -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)