Browse Source

Merge remote-tracking branch 'lcobucci/master'

Conflicts:
	src/Composer/Downloader/FileDownloader.php
Jordi Boggiano 11 years ago
parent
commit
016a016455

+ 1 - 1
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

+ 18 - 0
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
      *

+ 4 - 0
src/Composer/Package/Dumper/ArrayDumper.php

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

+ 4 - 0
src/Composer/Package/Loader/ArrayLoader.php

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

+ 1 - 0
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'])) {

+ 14 - 0
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();
 }

+ 21 - 0
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) {

+ 8 - 0
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'))

+ 4 - 0
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');

+ 4 - 0
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'))
             )
         );
     }

+ 1 - 0
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);

+ 10 - 0
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'
+                )
+            ),
         );
     }