1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-06-01 12:05:37 +02:00

[ticket/17048] Add method for getting composer in installer

PHPBB3-17048
This commit is contained in:
Marc Alexander 2022-10-19 20:44:17 +02:00
parent 09f2fe805c
commit ef2b3a1d68
No known key found for this signature in database
GPG Key ID: 50E0D2423696F995

View File

@ -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);