1
0
Fork 0

Merge pull request #9925 from Seldaek/dist_placeholders

Add support for mirror-style placeholders for the dist url
pull/9875/head
Jordi Boggiano 2021-06-02 10:05:25 +02:00 committed by GitHub
commit 35bfa453cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View File

@ -623,11 +623,16 @@ class Package extends BasePackage
if (!$url) { if (!$url) {
return array(); return array();
} }
if ($urlType === 'dist' && false !== strpos($url, '%')) {
$url = ComposerMirror::processUrl($url, $this->name, $this->version, $ref, $type, $this->prettyVersion);
}
$urls = array($url); $urls = array($url);
if ($mirrors) { if ($mirrors) {
foreach ($mirrors as $mirror) { foreach ($mirrors as $mirror) {
if ($urlType === 'dist') { 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') { } elseif ($urlType === 'source' && $type === 'git') {
$mirrorUrl = ComposerMirror::processGitUrl($mirror['url'], $this->name, $url, $type); $mirrorUrl = ComposerMirror::processGitUrl($mirror['url'], $this->name, $url, $type);
} elseif ($urlType === 'source' && $type === 'hg') { } elseif ($urlType === 'source' && $type === 'hg') {

View File

@ -19,18 +19,21 @@ namespace Composer\Util;
*/ */
class ComposerMirror class ComposerMirror
{ {
public static function processUrl($mirrorUrl, $packageName, $version, $reference, $type) public static function processUrl($mirrorUrl, $packageName, $version, $reference, $type, $prettyVersion = null)
{ {
if ($reference) { if ($reference) {
$reference = preg_match('{^([a-f0-9]*|%reference%)$}', $reference) ? $reference : md5($reference); $reference = preg_match('{^([a-f0-9]*|%reference%)$}', $reference) ? $reference : md5($reference);
} }
$version = strpos($version, '/') === false ? $version : md5($version); $version = strpos($version, '/') === false ? $version : md5($version);
return str_replace( $from = array('%package%', '%version%', '%reference%', '%type%');
array('%package%', '%version%', '%reference%', '%type%'), $to = array($packageName, $version, $reference, $type);
array($packageName, $version, $reference, $type), if (null !== $prettyVersion) {
$mirrorUrl $from[] = '%prettyVersion%';
); $to[] = $prettyVersion;
}
return str_replace($from, $to, $mirrorUrl);
} }
public static function processGitUrl($mirrorUrl, $packageName, $url, $type) public static function processGitUrl($mirrorUrl, $packageName, $url, $type)