Add composer mirror class
parent
9cbfe31983
commit
ba776c06ee
|
@ -88,8 +88,7 @@ class FileDownloader implements DownloaderInterface
|
||||||
$urls = $package->getDistUrls();
|
$urls = $package->getDistUrls();
|
||||||
while ($url = array_shift($urls)) {
|
while ($url = array_shift($urls)) {
|
||||||
try {
|
try {
|
||||||
$this->doDownload($package, $path, $url);
|
return $this->doDownload($package, $path, $url);
|
||||||
break;
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
if ($this->io->isDebug()) {
|
if ($this->io->isDebug()) {
|
||||||
$this->io->write('');
|
$this->io->write('');
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
namespace Composer\Package;
|
namespace Composer\Package;
|
||||||
|
|
||||||
use Composer\Package\Version\VersionParser;
|
use Composer\Package\Version\VersionParser;
|
||||||
|
use Composer\Util\ComposerMirror;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core package definitions that are needed to resolve dependencies and install packages
|
* Core package definitions that are needed to resolve dependencies and install packages
|
||||||
|
@ -581,14 +582,13 @@ class Package extends BasePackage
|
||||||
|
|
||||||
protected function getUrls($url, $mirrors, $ref, $type)
|
protected function getUrls($url, $mirrors, $ref, $type)
|
||||||
{
|
{
|
||||||
$urls = array($url);
|
$urls = array();
|
||||||
|
if ($url) {
|
||||||
|
$urls[] = $url;
|
||||||
|
}
|
||||||
if ($mirrors) {
|
if ($mirrors) {
|
||||||
foreach ($mirrors as $mirror) {
|
foreach ($mirrors as $mirror) {
|
||||||
$mirrorUrl = str_replace(
|
$mirrorUrl = ComposerMirror::processUrl($mirror['url'], $this->name, $this->version, $ref, $type);
|
||||||
array('%package%', '%version%', '%reference%', '%type%'),
|
|
||||||
array($this->name, $this->version, $ref, $type),
|
|
||||||
$mirror['url']
|
|
||||||
);
|
|
||||||
$func = $mirror['preferred'] ? 'array_unshift' : 'array_push';
|
$func = $mirror['preferred'] ? 'array_unshift' : 'array_push';
|
||||||
$func($urls, $mirrorUrl);
|
$func($urls, $mirrorUrl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Composer\Util;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ComposerMirror
|
||||||
|
{
|
||||||
|
public static function processUrl($mirrorUrl, $packageName, $version, $reference, $type)
|
||||||
|
{
|
||||||
|
$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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue