diff --git a/phpBB/phpbb/composer/installer.php b/phpBB/phpbb/composer/installer.php index aead83390d..330540378d 100644 --- a/phpBB/phpbb/composer/installer.php +++ b/phpBB/phpbb/composer/installer.php @@ -20,8 +20,10 @@ use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory; use Composer\IO\IOInterface; use Composer\IO\NullIO; use Composer\Json\JsonFile; +use Composer\Json\JsonValidationException; use Composer\Package\BasePackage; use Composer\Package\CompletePackage; +use Composer\PartialComposer; use Composer\Repository\ComposerRepository; use Composer\Semver\Constraint\ConstraintInterface; use Composer\Util\HttpDownloader; @@ -160,7 +162,8 @@ class installer $this->generate_ext_json_file($packages); - $composer = Factory::create($io, $this->get_composer_ext_json_filename(), false); + $composer = $this->get_composer($this->get_composer_ext_json_filename()); + $install = \Composer\Installer::create($io, $composer); $composer->getInstallationManager()->setOutputProgress(false); @@ -217,6 +220,32 @@ class installer }); } + /** + * Create instance of composer for supplied config file + * + * @param string|null $config_file Path to config file relative to phpBB root dir or null + * + * @return Composer|PartialComposer + * @throws JsonValidationException + */ + protected function get_composer(?string $config_file): PartialComposer + { + static $composer_factory; + if (!$composer_factory) + { + $composer_factory = new Factory(); + } + + $io = new NullIO(); + + return $composer_factory->createComposer( + $io, + $config_file, + false, + filesystem_helper::realpath('') + ); + } + /** * Returns the list of currently installed packages * @@ -232,19 +261,7 @@ class installer try { - static $composer_factory; - if (!$composer_factory) - { - $composer_factory = new Factory(); - } - - $io = new NullIO(); - $composer = $composer_factory->createComposer( - $io, - $this->get_composer_ext_json_filename(), - false, - filesystem_helper::realpath('') - ); + $composer = $this->get_composer($this->get_composer_ext_json_filename()); $installed = []; @@ -302,7 +319,7 @@ class installer $this->generate_ext_json_file($this->do_get_installed_packages(explode(',', self::PHPBB_TYPES))); $io = new NullIO(); - $composer = Factory::create($io, $this->get_composer_ext_json_filename(), false); + $composer = $this->get_composer($this->get_composer_ext_json_filename()); /** @var ConstraintInterface $core_constraint */ $core_constraint = $composer->getPackage()->getRequires()['phpbb/phpbb']->getConstraint(); @@ -489,7 +506,7 @@ class installer { $io = new NullIO(); - $composer = Factory::create($io, null, false); + $composer = $this->get_composer(null); $core_packages = $this->get_core_packages($composer);