Merge pull request #9925 from Seldaek/dist_placeholders
Add support for mirror-style placeholders for the dist urlpull/9875/head
commit
35bfa453cc
|
@ -623,11 +623,16 @@ class Package extends BasePackage
|
|||
if (!$url) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if ($urlType === 'dist' && false !== strpos($url, '%')) {
|
||||
$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') {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue