1
0
Fork 0

Reuse repository manager and others directly from the Composer instance, refs #9057

pull/9062/head
Jordi Boggiano 2020-07-17 12:05:07 +02:00
parent 1d3af13c22
commit eac03e16e7
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 11 additions and 21 deletions

View File

@ -288,13 +288,13 @@ EOT
} }
$composer = Factory::create($io, $config->all(), $disablePlugins); $composer = Factory::create($io, $config->all(), $disablePlugins);
$eventDispatcher = $composer->getEventDispatcher(); $config = $composer->getConfig();
$rm = $composer->getRepositoryManager();
if (null === $repository) { if (null === $repository) {
$rm = RepositoryFactory::manager($io, $config, $eventDispatcher, Factory::createRemoteFilesystem($io, $config));
$sourceRepo = new CompositeRepository(RepositoryFactory::defaultRepos($io, $config, $rm)); $sourceRepo = new CompositeRepository(RepositoryFactory::defaultRepos($io, $config, $rm));
} else { } else {
$sourceRepo = RepositoryFactory::fromString($io, $config, $repository, true); $sourceRepo = RepositoryFactory::fromString($io, $config, $repository, true, $rm);
} }
$parser = new VersionParser(); $parser = new VersionParser();
@ -389,13 +389,13 @@ EOT
$package = $package->getAliasOf(); $package = $package->getAliasOf();
} }
$dm = $this->createDownloadManager($io, $config, $eventDispatcher); $dm = $composer->getDownloadManager();
$dm->setPreferSource($preferSource) $dm->setPreferSource($preferSource)
->setPreferDist($preferDist) ->setPreferDist($preferDist)
->setOutputProgress(!$noProgress); ->setOutputProgress(!$noProgress);
$projectInstaller = new ProjectInstaller($directory, $dm); $projectInstaller = new ProjectInstaller($directory, $dm);
$im = $this->createInstallationManager(); $im = $composer->getInstallationManager();
$im->addInstaller($projectInstaller); $im->addInstaller($projectInstaller);
$im->install(new InstalledFilesystemRepository(new JsonFile('php://memory')), new InstallOperation($package)); $im->install(new InstalledFilesystemRepository(new JsonFile('php://memory')), new InstallOperation($package));
$im->notifyInstalls($io); $im->notifyInstalls($io);
@ -413,16 +413,4 @@ EOT
return $installedFromVcs; return $installedFromVcs;
} }
protected function createDownloadManager(IOInterface $io, Config $config, EventDispatcher $eventDispatcher)
{
$factory = new Factory();
return $factory->createDownloadManager($io, $config, $eventDispatcher);
}
protected function createInstallationManager()
{
return new InstallationManager();
}
} }

View File

@ -62,11 +62,11 @@ class RepositoryFactory
* @param bool $allowFilesystem * @param bool $allowFilesystem
* @return RepositoryInterface * @return RepositoryInterface
*/ */
public static function fromString(IOInterface $io, Config $config, $repository, $allowFilesystem = false) public static function fromString(IOInterface $io, Config $config, $repository, $allowFilesystem = false, RepositoryManager $rm = null)
{ {
$repoConfig = static::configFromString($io, $config, $repository, $allowFilesystem); $repoConfig = static::configFromString($io, $config, $repository, $allowFilesystem);
return static::createRepo($io, $config, $repoConfig); return static::createRepo($io, $config, $repoConfig, $rm);
} }
/** /**
@ -75,9 +75,11 @@ class RepositoryFactory
* @param array $repoConfig * @param array $repoConfig
* @return RepositoryInterface * @return RepositoryInterface
*/ */
public static function createRepo(IOInterface $io, Config $config, array $repoConfig) public static function createRepo(IOInterface $io, Config $config, array $repoConfig, RepositoryManager $rm = null)
{ {
if (!$rm) {
$rm = static::manager($io, $config, null, Factory::createRemoteFilesystem($io, $config)); $rm = static::manager($io, $config, null, Factory::createRemoteFilesystem($io, $config));
}
$repos = static::createRepos($rm, array($repoConfig)); $repos = static::createRepos($rm, array($repoConfig));
return reset($repos); return reset($repos);