Merge remote-tracking branch 'dpb587/multiple-repos'
Conflicts: src/Composer/Factory.php src/Composer/Package/Loader/RootPackageLoader.php tests/Composer/Test/Package/Loader/RootPackageLoaderTest.phppull/824/merge
commit
4a6ae454c2
|
@ -17,6 +17,7 @@ use Composer\Installer;
|
|||
use Composer\Installer\ProjectInstaller;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Repository\ComposerRepository;
|
||||
use Composer\Repository\CompositeRepository;
|
||||
use Composer\Repository\FilesystemRepository;
|
||||
use Composer\Repository\InstalledFilesystemRepository;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
@ -90,7 +91,7 @@ EOT
|
|||
|
||||
$config = Factory::createConfig();
|
||||
if (null === $repositoryUrl) {
|
||||
$sourceRepo = new ComposerRepository(array('url' => 'http://packagist.org'), $io, $config);
|
||||
$sourceRepo = new CompositeRepository(Factory::createComposerRepositories($io, $config));
|
||||
} elseif ("json" === pathinfo($repositoryUrl, PATHINFO_EXTENSION)) {
|
||||
$sourceRepo = new FilesystemRepository(new JsonFile($repositoryUrl, new RemoteFilesystem($io)));
|
||||
} elseif (0 === strpos($repositoryUrl, 'http')) {
|
||||
|
|
|
@ -234,9 +234,9 @@ EOT
|
|||
|
||||
// init repos
|
||||
if (!$this->repos) {
|
||||
$this->repos = new CompositeRepository(array(
|
||||
new PlatformRepository,
|
||||
new ComposerRepository(array('url' => 'http://packagist.org'), $this->getIO(), Factory::createConfig())
|
||||
$this->repos = new CompositeRepository(array_merge(
|
||||
array(new PlatformRepository),
|
||||
Factory::createComposerRepositories($this->getIO(), Factory::createConfig())
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -53,10 +53,10 @@ EOT
|
|||
$installedRepo = new CompositeRepository(array($localRepo, $platformRepo));
|
||||
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
|
||||
} else {
|
||||
$output->writeln('No composer.json found in the current directory, showing packages from packagist.org');
|
||||
$defaultRepos = Factory::createComposerRepositories($this->getIO(), Factory::createConfig());
|
||||
$output->writeln('No composer.json found in the current directory, showing packages from ' . str_replace('http://', '', implode(', ', array_keys($defaultRepos))));
|
||||
$installedRepo = $platformRepo;
|
||||
$packagist = new ComposerRepository(array('url' => 'http://packagist.org'), $this->getIO(), Factory::createConfig());
|
||||
$repos = new CompositeRepository(array($installedRepo, $packagist));
|
||||
$repos = new CompositeRepository(array_merge(array($installedRepo), $defaultRepos));
|
||||
}
|
||||
|
||||
$tokens = $input->getArgument('tokens');
|
||||
|
|
|
@ -64,10 +64,10 @@ EOT
|
|||
$installedRepo = new CompositeRepository(array($localRepo, $platformRepo));
|
||||
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
|
||||
} else {
|
||||
$output->writeln('No composer.json found in the current directory, showing packages from packagist.org');
|
||||
$defaultRepos = Factory::createComposerRepositories($this->getIO(), Factory::createConfig());
|
||||
$output->writeln('No composer.json found in the current directory, showing packages from ' . str_replace('http://', '', implode(', ', array_keys($defaultRepos))));
|
||||
$installedRepo = $platformRepo;
|
||||
$packagist = new ComposerRepository(array('url' => 'http://packagist.org'), $this->getIO(), Factory::createConfig());
|
||||
$repos = new CompositeRepository(array($installedRepo, $packagist));
|
||||
$repos = new CompositeRepository(array_merge(array($installedRepo), $defaultRepos));
|
||||
}
|
||||
|
||||
// show single package or single version
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace Composer;
|
|||
|
||||
use Composer\Json\JsonFile;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Repository\ComposerRepository;
|
||||
use Composer\Repository\RepositoryManager;
|
||||
use Composer\Util\ProcessExecutor;
|
||||
use Composer\Util\RemoteFilesystem;
|
||||
|
@ -27,6 +28,10 @@ use Composer\Util\RemoteFilesystem;
|
|||
*/
|
||||
class Factory
|
||||
{
|
||||
public static $defaultComposerRepositories = array(
|
||||
'packagist' => 'http://packagist.org',
|
||||
);
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
|
@ -67,6 +72,17 @@ class Factory
|
|||
return getenv('COMPOSER') ?: 'composer.json';
|
||||
}
|
||||
|
||||
public static function createComposerRepositories(IOInterface $io, Config $config)
|
||||
{
|
||||
$repos = array();
|
||||
|
||||
foreach (static::$defaultComposerRepositories as $url) {
|
||||
$repos[$url] = new ComposerRepository(array('url' => $url), $io, $config);
|
||||
}
|
||||
|
||||
return $repos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Composer instance
|
||||
*
|
||||
|
@ -114,8 +130,8 @@ class Factory
|
|||
// initialize repository manager
|
||||
$rm = $this->createRepositoryManager($io, $config);
|
||||
|
||||
// load default repository unless it's explicitly disabled
|
||||
$localConfig = $this->addPackagistRepository($localConfig);
|
||||
// load default composer repositories unless they're explicitly disabled
|
||||
$localConfig = $this->addComposerRepositories($localConfig);
|
||||
|
||||
// load local repository
|
||||
$this->addLocalRepository($rm, $vendorDir);
|
||||
|
@ -186,31 +202,35 @@ class Factory
|
|||
* @param array $localConfig
|
||||
* @return array
|
||||
*/
|
||||
protected function addPackagistRepository(array $localConfig)
|
||||
protected function addComposerRepositories(array $localConfig)
|
||||
{
|
||||
$loadPackagist = true;
|
||||
$packagistConfig = array(
|
||||
'type' => 'composer',
|
||||
'url' => 'http://packagist.org'
|
||||
);
|
||||
$defaults = static::$defaultComposerRepositories;
|
||||
|
||||
if (isset($localConfig['repositories'])) {
|
||||
foreach ($localConfig['repositories'] as $key => $repo) {
|
||||
if (isset($repo['packagist'])) {
|
||||
if (true === $repo['packagist']) {
|
||||
$localConfig['repositories'][$key] = $packagistConfig;
|
||||
}
|
||||
foreach ($defaults as $name => $url) {
|
||||
if (isset($repo[$name])) {
|
||||
if (true === $repo[$name]) {
|
||||
$localConfig['repositories'][$key] = array(
|
||||
'type' => 'composer',
|
||||
'url' => $url,
|
||||
);
|
||||
}
|
||||
|
||||
$loadPackagist = false;
|
||||
break;
|
||||
unset($defaults[$name]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$localConfig['repositories'] = array();
|
||||
}
|
||||
|
||||
if ($loadPackagist) {
|
||||
$localConfig['repositories'][] = $packagistConfig;
|
||||
foreach ($defaults as $name => $url) {
|
||||
$localConfig['repositories'][] = array(
|
||||
'type' => 'composer',
|
||||
'url' => $url,
|
||||
);
|
||||
}
|
||||
|
||||
return $localConfig;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
namespace Composer\Package\Loader;
|
||||
|
||||
use Composer\Package\BasePackage;
|
||||
use Composer\Factory;
|
||||
use Composer\Package\Version\VersionParser;
|
||||
use Composer\Repository\RepositoryManager;
|
||||
use Composer\Util\ProcessExecutor;
|
||||
|
@ -79,10 +80,14 @@ class RootPackageLoader extends ArrayLoader
|
|||
$package->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability']));
|
||||
}
|
||||
|
||||
$defaultRepositories = array_keys(Factory::$defaultComposerRepositories);
|
||||
|
||||
if (isset($config['repositories'])) {
|
||||
foreach ($config['repositories'] as $index => $repo) {
|
||||
if (isset($repo['packagist']) && $repo['packagist'] === false) {
|
||||
continue;
|
||||
foreach ($defaultRepositories as $name) {
|
||||
if (isset($repo[$name]) && $repo[$name] === false) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
if (!is_array($repo)) {
|
||||
throw new \UnexpectedValueException('Repository '.$index.' should be an array, '.gettype($repo).' given');
|
||||
|
|
|
@ -16,14 +16,31 @@ use Composer\Factory;
|
|||
|
||||
class FactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $defaultComposerRepositories;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->defaultComposerRepositories = Factory::$defaultComposerRepositories;
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
Factory::$defaultComposerRepositories = $this->defaultComposerRepositories;
|
||||
unset($this->defaultComposerRepositories);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataAddPackagistRepository
|
||||
*/
|
||||
public function testAddPackagistRepository($expected, $config)
|
||||
public function testAddPackagistRepository($expected, $config, $defaults = null)
|
||||
{
|
||||
if (null !== $defaults) {
|
||||
Factory::$defaultComposerRepositories = $defaults;
|
||||
}
|
||||
|
||||
$factory = new Factory();
|
||||
|
||||
$ref = new \ReflectionMethod($factory, 'addPackagistRepository');
|
||||
$ref = new \ReflectionMethod($factory, 'addComposerRepositories');
|
||||
$ref->setAccessible(true);
|
||||
|
||||
$this->assertEquals($expected, $ref->invoke($factory, $config));
|
||||
|
@ -61,6 +78,29 @@ class FactoryTest extends \PHPUnit_Framework_TestCase
|
|||
)
|
||||
);
|
||||
|
||||
$multirepo = array(
|
||||
'example.com' => 'http://example.com',
|
||||
'packagist' => 'http://packagist.org',
|
||||
);
|
||||
|
||||
$data[] = array(
|
||||
$f(
|
||||
array('type' => 'composer', 'url' => 'http://example.com'),
|
||||
array('type' => 'composer', 'url' => 'http://packagist.org')
|
||||
),
|
||||
$f(),
|
||||
$multirepo,
|
||||
);
|
||||
|
||||
$data[] = array(
|
||||
$f(
|
||||
array('type' => 'composer', 'url' => 'http://packagist.org'),
|
||||
array('type' => 'composer', 'url' => 'http://example.com')
|
||||
),
|
||||
$f(array('packagist' => true)),
|
||||
$multirepo,
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace Composer\Test\Package\Loader;
|
|||
|
||||
use Composer\Package\Loader\RootPackageLoader;
|
||||
use Composer\Test\Mock\ProcessExecutorMock;
|
||||
use Composer\Repository\RepositoryManager;
|
||||
|
||||
class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
@ -45,4 +46,19 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$this->assertEquals("dev-$commitHash", $package->getVersion());
|
||||
}
|
||||
|
||||
public function testAllowsDisabledDefaultRepository()
|
||||
{
|
||||
$loader = new RootPackageLoader(
|
||||
new RepositoryManager(
|
||||
$this->getMock('Composer\\IO\\IOInterface'),
|
||||
$this->getMock('Composer\\Config')
|
||||
)
|
||||
);
|
||||
|
||||
$repos = array(array('packagist' => false));
|
||||
$package = $loader->load(array('repositories' => $repos));
|
||||
|
||||
$this->assertEquals($repos, $package->getRepositories());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue