From eac03e16e7213e2ddc7e73818e91a0f21e571bda Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 17 Jul 2020 12:05:07 +0200 Subject: [PATCH] Reuse repository manager and others directly from the Composer instance, refs #9057 --- src/Composer/Command/CreateProjectCommand.php | 22 +++++-------------- src/Composer/Repository/RepositoryFactory.php | 10 +++++---- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 6e41e64ac..1e52674ba 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -288,13 +288,13 @@ EOT } $composer = Factory::create($io, $config->all(), $disablePlugins); - $eventDispatcher = $composer->getEventDispatcher(); + $config = $composer->getConfig(); + $rm = $composer->getRepositoryManager(); if (null === $repository) { - $rm = RepositoryFactory::manager($io, $config, $eventDispatcher, Factory::createRemoteFilesystem($io, $config)); $sourceRepo = new CompositeRepository(RepositoryFactory::defaultRepos($io, $config, $rm)); } else { - $sourceRepo = RepositoryFactory::fromString($io, $config, $repository, true); + $sourceRepo = RepositoryFactory::fromString($io, $config, $repository, true, $rm); } $parser = new VersionParser(); @@ -389,13 +389,13 @@ EOT $package = $package->getAliasOf(); } - $dm = $this->createDownloadManager($io, $config, $eventDispatcher); + $dm = $composer->getDownloadManager(); $dm->setPreferSource($preferSource) ->setPreferDist($preferDist) ->setOutputProgress(!$noProgress); $projectInstaller = new ProjectInstaller($directory, $dm); - $im = $this->createInstallationManager(); + $im = $composer->getInstallationManager(); $im->addInstaller($projectInstaller); $im->install(new InstalledFilesystemRepository(new JsonFile('php://memory')), new InstallOperation($package)); $im->notifyInstalls($io); @@ -413,16 +413,4 @@ EOT 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(); - } } diff --git a/src/Composer/Repository/RepositoryFactory.php b/src/Composer/Repository/RepositoryFactory.php index 9bca0bd07..cf2c79dec 100644 --- a/src/Composer/Repository/RepositoryFactory.php +++ b/src/Composer/Repository/RepositoryFactory.php @@ -62,11 +62,11 @@ class RepositoryFactory * @param bool $allowFilesystem * @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); - return static::createRepo($io, $config, $repoConfig); + return static::createRepo($io, $config, $repoConfig, $rm); } /** @@ -75,9 +75,11 @@ class RepositoryFactory * @param array $repoConfig * @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) { - $rm = static::manager($io, $config, null, Factory::createRemoteFilesystem($io, $config)); + if (!$rm) { + $rm = static::manager($io, $config, null, Factory::createRemoteFilesystem($io, $config)); + } $repos = static::createRepos($rm, array($repoConfig)); return reset($repos);