From c3a41b944ea3b6fb9b2ddf1f1ccd62fa88cfe7b6 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Tue, 15 Mar 2022 10:29:25 -0400 Subject: [PATCH] Allow global ignore-platform-req (#10616) --- doc/03-cli.md | 8 ++++++++ src/Composer/Command/BaseCommand.php | 21 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/03-cli.md b/doc/03-cli.md index e5089f45f..b76891b6f 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -1174,3 +1174,11 @@ useful for plugin authors to identify what is firing when exactly. If set to `1`, it is the equivalent of passing the `--no-dev` argument to `install` or `update`. You can override this for a single command by setting `COMPOSER_NO_DEV=0`. + +### COMPOSER_IGNORE_PLATFORM_REQ or COMPOSER_IGNORE_PLATFORM_REQS + +If `COMPOSER_IGNORE_PLATFORM_REQS` set to `1`, it is the equivalent of passing the `--ignore-platform-reqs` argument. +Otherwise, specifying a comma separated list in `COMPOSER_IGNORE_PLATFORM_REQ` will ignore those specific requirements. + +For example, if a development workstation will never run database queries, this can be used to ignore the requirement for the database extensions to be available. +If you set `COMPOSER_IGNORE_PLATFORM_REQ=ext-oci8`, then composer will allow packages to be installed even if the `oci8` PHP extension is not enabled. diff --git a/src/Composer/Command/BaseCommand.php b/src/Composer/Command/BaseCommand.php index 930cde9d5..2563442ea 100644 --- a/src/Composer/Command/BaseCommand.php +++ b/src/Composer/Command/BaseCommand.php @@ -198,6 +198,8 @@ abstract class BaseCommand extends Command } $composer = $this->tryComposer($disablePlugins, $disableScripts); + $io = $this->getIO(); + if (null === $composer) { $composer = Factory::createGlobal($this->getIO(), $disablePlugins, $disableScripts); } @@ -210,12 +212,29 @@ abstract class BaseCommand extends Command $input->setOption('no-progress', true); } - if (true == $input->hasOption('no-dev')) { + if (true === $input->hasOption('no-dev')) { if (!$input->getOption('no-dev') && true == Platform::getEnv('COMPOSER_NO_DEV')) { $input->setOption('no-dev', true); } } + if (true === $input->hasOption('ignore-platform-reqs')) { + if (!$input->getOption('ignore-platform-reqs') && true == Platform::getEnv('COMPOSER_IGNORE_PLATFORM_REQS')) { + $input->setOption('ignore-platform-reqs', true); + + $io->writeError('COMPOSER_IGNORE_PLATFORM_REQS is set. You may experience unexpected errors.'); + } + } + + if (true === $input->hasOption('ignore-platform-req') && (!$input->hasOption('ignore-platform-reqs') || !$input->getOption('ignore-platform-reqs'))) { + $ignorePlatformReqEnv = Platform::getEnv('COMPOSER_IGNORE_PLATFORM_REQ'); + if (0 === count($input->getOption('ignore-platform-req')) && is_string($ignorePlatformReqEnv) && '' !== $ignorePlatformReqEnv) { + $input->setOption('ignore-platform-req', explode(',', $ignorePlatformReqEnv)); + + $io->writeError('COMPOSER_IGNORE_PLATFORM_REQ is set to ignore '.$ignorePlatformReqEnv.'. You may experience unexpected errors.'); + } + } + parent::initialize($input, $output); }