Skip to content

Commit 3693210

Browse files
committed
Ignore platform reqs if env var or input option present
1 parent 7692a62 commit 3693210

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/MergePlugin.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Composer\Plugin\PluginInterface;
2525
use Composer\Script\Event as ScriptEvent;
2626
use Composer\Script\ScriptEvents;
27+
use Symfony\Component\Console\Input\ArgvInput;
2728

2829
/**
2930
* Composer plugin that allows merging multiple composer.json files.
@@ -373,13 +374,32 @@ public function onPostInstallOrUpdate(ScriptEvent $event)
373374
$installer->setUpdate(true);
374375

375376
if ($this->state->isComposer1()) {
376-
// setUpdateWhitelist() only exists in composer 1.x. Configure as to run phan against composer 2.x
377+
// setUpdateWhitelist() only exists in composer 1.x.
378+
// Configure as to run phan against composer 2.x
377379
// @phan-suppress-next-line PhanUndeclaredMethod
378380
$installer->setUpdateWhitelist($requirements);
379381
} else {
380382
$installer->setUpdateAllowList($requirements);
381383
}
382384

385+
// Respect --ignore-platform-reqs option from input or
386+
// COMPOSER_IGNORE_PLATFORM_REQS environment variable.
387+
$input = new ArgvInput();
388+
if ($this->state->isComposer1()) {
389+
// setIgnorePlatformRequirements only exists in composer 1.x.
390+
// Configure as to run phan against composer 2.x
391+
// @phan-suppress-next-line PhanUndeclaredMethod
392+
$installer->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'));
393+
} else {
394+
$ignore_platform_reqs = getenv('COMPOSER_IGNORE_PLATFORM_REQS') ??
395+
$input->getOption('ignore-platform-reqs');
396+
$ignore_platform_reqs =
397+
\Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory::fromBoolOrList(
398+
$ignore_platform_reqs
399+
);
400+
$installer->setPlatformRequirementFilter($ignore_platform_reqs);
401+
}
402+
383403
$status = $installer->run();
384404
if (( $status !== 0 ) && $lockBackup && $lock && !$this->state->isComposer1()) {
385405
$this->logger->log(

0 commit comments

Comments
 (0)