From 2e2b66b16e16d3b67e478c33f601f1ad8c7808c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Mon, 19 Aug 2013 04:36:57 -0300 Subject: [PATCH 1/5] Package should have download options --- src/Composer/Package/BasePackage.php | 18 ++++++++++++++++++ src/Composer/Package/PackageInterface.php | 14 ++++++++++++++ 2 files changed, 32 insertions(+) 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/PackageInterface.php b/src/Composer/Package/PackageInterface.php index a3c8a2793..1b1e99707 100644 --- a/src/Composer/Package/PackageInterface.php +++ b/src/Composer/Package/PackageInterface.php @@ -301,4 +301,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(); } From d4043b6b9a01bc583a590902d827a4bd5aeb66d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Mon, 19 Aug 2013 04:38:25 -0300 Subject: [PATCH 2/5] Package options must be passed as argument to downloader --- src/Composer/Downloader/FileDownloader.php | 4 ++-- tests/Composer/Test/Downloader/FileDownloaderTest.php | 8 ++++++++ tests/Composer/Test/Downloader/ZipDownloaderTest.php | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 8ed0712bf..38b2fe304 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -103,7 +103,7 @@ class FileDownloader implements DownloaderInterface $retries = 3; while ($retries--) { try { - $this->rfs->copy($hostname, $processedUrl, $fileName, $this->outputProgress); + $this->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 @@ -132,7 +132,7 @@ class FileDownloader implements DownloaderInterface ) { throw $e; } - $this->rfs->copy($hostname, $processedUrl, $fileName, $this->outputProgress); + $this->rfs->copy($hostname, $processedUrl, $fileName, $this->outputProgress, $package->getOptions()); } else { throw $e; } diff --git a/tests/Composer/Test/Downloader/FileDownloaderTest.php b/tests/Composer/Test/Downloader/FileDownloaderTest.php index 99dcaab18..a6f3f1984 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()); @@ -130,6 +134,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'); From 28d0e087854558f5c133a9efc030efa8c9e9bf4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Mon, 19 Aug 2013 04:39:13 -0300 Subject: [PATCH 3/5] Package options should be dumped if exists --- src/Composer/Package/Dumper/ArrayDumper.php | 4 ++++ tests/Composer/Test/Package/Dumper/ArrayDumperTest.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Composer/Package/Dumper/ArrayDumper.php b/src/Composer/Package/Dumper/ArrayDumper.php index bca932d71..0fea4578d 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/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')) ) ); } From 8630aab93f03efd2c1e74a7e0498ed702c9a6598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Mon, 19 Aug 2013 04:40:08 -0300 Subject: [PATCH 4/5] Package options must be a non mandatory array and should be loaded when exists --- src/Composer/Package/Loader/ArrayLoader.php | 4 ++++ src/Composer/Package/Loader/ValidatingArrayLoader.php | 1 + tests/Composer/Test/Package/Loader/ArrayLoaderTest.php | 1 + .../Test/Package/Loader/ValidatingArrayLoaderTest.php | 10 ++++++++++ 4 files changed, 16 insertions(+) diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index 3940bdeb0..46e33b37d 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -193,6 +193,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 a5b6281a3..8e21b0e91 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -196,6 +196,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/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 262c24bf6..b069c3e82 100644 --- a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php @@ -143,6 +143,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 @@ -256,6 +257,15 @@ class ValidatingArrayLoaderTest extends \PHPUnit_Framework_TestCase 'autoload : invalid value (psr0), must be one of psr-0, classmap, files' ) ), + array( + array( + 'name' => 'foo/bar', + 'options' => 'test', + ), + array( + 'options : should be an array, string given' + ) + ), ); } From 0b77a59af66c7611307139aec49014fbe2db3d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Mon, 19 Aug 2013 04:40:54 -0300 Subject: [PATCH 5/5] Repository options must be replicated on package when dist file is under repository base dir --- .../Repository/ComposerRepository.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 5eab777a4..2b6dd2385 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; @@ -204,10 +205,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} */ @@ -376,6 +386,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) {