diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 5ff27d18f..3e2a2972d 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -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 diff --git a/src/Composer/Package/BasePackage.php b/src/Composer/Package/BasePackage.php index a783ca7fc..afc20f4b6 100644 --- a/src/Composer/Package/BasePackage.php +++ b/src/Composer/Package/BasePackage.php @@ -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 * diff --git a/src/Composer/Package/Dumper/ArrayDumper.php b/src/Composer/Package/Dumper/ArrayDumper.php index 0a183742f..b81912837 100644 --- a/src/Composer/Package/Dumper/ArrayDumper.php +++ b/src/Composer/Package/Dumper/ArrayDumper.php @@ -108,6 +108,10 @@ class ArrayDumper } } + if (count($package->getOptions()) > 0) { + $data['options'] = $package->getOptions(); + } + return $data; } diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index 6ef4e7c03..23c305d0d 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -197,6 +197,10 @@ class ArrayLoader implements LoaderInterface } } + if (isset($config['options'])) { + $package->setOptions($config['options']); + } + return $package; } diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index ddd9ca328..ac8010459 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -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'])) { diff --git a/src/Composer/Package/PackageInterface.php b/src/Composer/Package/PackageInterface.php index fd7393992..ea3a86420 100644 --- a/src/Composer/Package/PackageInterface.php +++ b/src/Composer/Package/PackageInterface.php @@ -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(); } diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 37f6d810b..529128dd7 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -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) { diff --git a/tests/Composer/Test/Downloader/FileDownloaderTest.php b/tests/Composer/Test/Downloader/FileDownloaderTest.php index db6f81a5e..9fb34b846 100644 --- a/tests/Composer/Test/Downloader/FileDownloaderTest.php +++ b/tests/Composer/Test/Downloader/FileDownloaderTest.php @@ -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')) diff --git a/tests/Composer/Test/Downloader/ZipDownloaderTest.php b/tests/Composer/Test/Downloader/ZipDownloaderTest.php index bbe77d7ee..441777d8c 100644 --- a/tests/Composer/Test/Downloader/ZipDownloaderTest.php +++ b/tests/Composer/Test/Downloader/ZipDownloaderTest.php @@ -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'); diff --git a/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php b/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php index 4b9877523..54e8de9cc 100644 --- a/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php +++ b/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php @@ -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')) ) ); } diff --git a/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php b/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php index 248e251ef..474929307 100644 --- a/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php @@ -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); diff --git a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php b/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php index 09bb4afd9..45e3f454c 100644 --- a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php @@ -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' + ) + ), ); }