1
0
Fork 0

Merge remote-tracking branch 'lcobucci/master'

Conflicts:
	src/Composer/Downloader/FileDownloader.php
pull/2604/head
Jordi Boggiano 2014-05-07 18:02:46 +02:00
commit 016a016455
12 changed files with 90 additions and 1 deletions

View File

@ -118,7 +118,7 @@ class FileDownloader implements DownloaderInterface
$retries = 3;
while ($retries--) {
try {
$rfs->copy($hostname, $processedUrl, $fileName, $this->outputProgress);
$rfs->copy($hostname, $processedUrl, $fileName, $this->outputProgress, $package->getOptions());
break;
} catch (TransportException $e) {
// if we got an http response with a proper code, then requesting again will probably not help, abort

View File

@ -49,6 +49,7 @@ abstract class BasePackage implements PackageInterface
protected $repository;
protected $id;
protected $options;
/**
* All descendants' constructors should call this parent constructor
@ -60,6 +61,7 @@ abstract class BasePackage implements PackageInterface
$this->prettyName = $name;
$this->name = strtolower($name);
$this->id = -1;
$this->options = array();
}
/**
@ -133,6 +135,22 @@ abstract class BasePackage implements PackageInterface
return $this->repository;
}
/**
* {@inheritDoc}
*/
public function getOptions()
{
return $this->options;
}
/**
* {@inheritDoc}
*/
public function setOptions(array $options)
{
$this->options = $options;
}
/**
* checks if this package is a platform package
*

View File

@ -108,6 +108,10 @@ class ArrayDumper
}
}
if (count($package->getOptions()) > 0) {
$data['options'] = $package->getOptions();
}
return $data;
}

View File

@ -197,6 +197,10 @@ class ArrayLoader implements LoaderInterface
}
}
if (isset($config['options'])) {
$package->setOptions($config['options']);
}
return $package;
}

View File

@ -230,6 +230,7 @@ class ValidatingArrayLoader implements LoaderInterface
// TODO validate package repositories' packages using this recursively
$this->validateFlatArray('include-path');
$this->validateArray('options');
// branch alias validation
if (isset($this->config['extra']['branch-alias'])) {

View File

@ -313,4 +313,18 @@ interface PackageInterface
* @return array
*/
public function getArchiveExcludes();
/**
* Configures the list of options to download package dist files
*
* @param array $options
*/
public function setOptions(array $options);
/**
* Returns a list of options to download package dist files
*
* @return array
*/
public function getOptions();
}

View File

@ -13,6 +13,7 @@
namespace Composer\Repository;
use Composer\Package\Loader\ArrayLoader;
use Composer\Package\Package;
use Composer\Package\PackageInterface;
use Composer\Package\AliasPackage;
use Composer\Package\Version\VersionParser;
@ -209,10 +210,19 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
$package = $package->getAliasOf();
}
$package->setRepository($this);
$this->configurePackageOptions($package);
return $package;
}
protected function configurePackageOptions(PackageInterface $package)
{
if ($package instanceof Package
&& strpos($package->getDistUrl(), $this->baseUrl) === 0) {
$package->setOptions($this->options);
}
}
/**
* {@inheritDoc}
*/
@ -381,6 +391,17 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
}
}
/**
* Adds a new package to the repository
*
* @param PackageInterface $package
*/
public function addPackage(PackageInterface $package)
{
parent::addPackage($package);
$this->configurePackageOptions($package);
}
protected function loadRootServerFile()
{
if (null !== $this->rootData) {

View File

@ -89,6 +89,10 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase
->method('getDistUrl')
->will($this->returnValue('http://example.com/script.js'))
;
$packageMock->expects($this->atLeastOnce())
->method('getOptions')
->will($this->returnValue(array()))
;
do {
$path = sys_get_temp_dir().'/'.md5(time().mt_rand());
@ -161,6 +165,10 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase
->method('getDistUrl')
->will($this->returnValue('http://example.com/script.js'))
;
$packageMock->expects($this->atLeastOnce())
->method('getOptions')
->will($this->returnValue(array()))
;
$packageMock->expects($this->any())
->method('getDistSha1Checksum')
->will($this->returnValue('invalid'))

View File

@ -30,6 +30,10 @@ class ZipDownloaderTest extends \PHPUnit_Framework_TestCase
->method('getDistUrl')
->will($this->returnValue('file://'.__FILE__))
;
$packageMock->expects($this->atLeastOnce())
->method('getOptions')
->will($this->returnValue(array()))
;
$io = $this->getMock('Composer\IO\IOInterface');
$config = $this->getMock('Composer\Config');

View File

@ -194,6 +194,10 @@ class ArrayDumperTest extends \PHPUnit_Framework_TestCase
array(new Link('foo', 'foo/bar', new VersionConstraint('=', '1.0.0.0'), 'requires', '1.0.0'), new Link('bar', 'bar/baz', new VersionConstraint('=', '1.0.0.0'), 'requires', '1.0.0')),
'conflicts',
array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0')
),
array(
'options',
array('ssl' => array('local_cert' => '/opt/certs/test.pem'))
)
);
}

View File

@ -117,6 +117,7 @@ class ArrayLoaderTest extends \PHPUnit_Framework_TestCase
'archive' => array(
'exclude' => array('/foo/bar', 'baz', '!/foo/bar/baz'),
),
'options' => array('ssl' => array('local_cert' => '/opt/certs/test.pem'))
);
$package = $this->loader->load($config);

View File

@ -146,6 +146,7 @@ class ValidatingArrayLoaderTest extends \PHPUnit_Framework_TestCase
'bin/foo',
'bin/bar',
),
'options' => array('ssl' => array('local_cert' => '/opt/certs/test.pem'))
),
),
array( // test as array
@ -263,6 +264,15 @@ class ValidatingArrayLoaderTest extends \PHPUnit_Framework_TestCase
'autoload : invalid value (psr0), must be one of psr-0, psr-4, classmap, files'
)
),
array(
array(
'name' => 'foo/bar',
'options' => 'test',
),
array(
'options : should be an array, string given'
)
),
);
}