1
0
Fork 0

Fix dist urls for lock files and hardcoded references

pull/1155/head
Jordi Boggiano 2012-09-27 20:22:08 +02:00
parent 8a35353e8d
commit 027037bb9f
4 changed files with 11 additions and 5 deletions

View File

@ -85,8 +85,12 @@ abstract class ArchiveDownloader extends FileDownloader
/**
* {@inheritdoc}
*/
protected function processUrl($url)
protected function processUrl(PackageInterface $package, $url)
{
if ($package->getDistReference() && preg_match('{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i', $url, $match)) {
$url = 'https://github.com/' . $match[1] . '/'. $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference();
}
if (!extension_loaded('openssl') && (0 === strpos($url, 'https:') || 0 === strpos($url, 'http://github.com'))) {
// bypass https for github if openssl is disabled
if (preg_match('{^https?://(github.com/[^/]+/[^/]+/(zip|tar)ball/[^/]+)$}i', $url, $match)) {
@ -96,7 +100,7 @@ abstract class ArchiveDownloader extends FileDownloader
}
}
return $url;
return parent::processUrl($package, $url);
}
/**

View File

@ -67,7 +67,7 @@ class FileDownloader implements DownloaderInterface
$this->io->write(" - Installing <info>" . $package->getName() . "</info> (<comment>" . VersionParser::formatVersion($package) . "</comment>)");
$processUrl = $this->processUrl($url);
$processUrl = $this->processUrl($package, $url);
try {
$this->rfs->copy($package->getSourceUrl(), $processUrl, $fileName);
@ -123,12 +123,13 @@ class FileDownloader implements DownloaderInterface
/**
* Process the download url
*
* @param PackageInterface $package package the url is coming from
* @param string $url download url
* @return string url
*
* @throws \RuntimeException If any problem with the url
*/
protected function processUrl($url)
protected function processUrl(PackageInterface $package, $url)
{
if (!extension_loaded('openssl') && 0 === strpos($url, 'https:')) {
throw new \RuntimeException('You must enable the openssl extension to download files via https');

View File

@ -481,6 +481,7 @@ class Installer
$references = $this->package->getReferences();
if (isset($references[$package->getName()])) {
$package->setSourceReference($references[$package->getName()]);
$package->setDistReference($references[$package->getName()]);
}
}
}

View File

@ -38,7 +38,7 @@ class ArchiveDownloaderTest extends \PHPUnit_Framework_TestCase
$method->setAccessible(true);
$expected = 'https://github.com/composer/composer/zipball/master';
$url = $method->invoke($downloader, $expected);
$url = $method->invoke($downloader, $this->getMock('Composer\Package\PackageInterface'), $expected);
if (extension_loaded('openssl')) {
$this->assertEquals($expected, $url);