Skip to content

Commit 09e9d08

Browse files
committed
Only update composer/installers as needed
1 parent bfd304c commit 09e9d08

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

contribution/extension/type.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,15 @@ protected function update_phpbb_requirement(array $data)
371371
}
372372

373373
// Composer installers must be required by all extensions in order to be installed correctly
374-
$data['require']['composer/installers'] = '~1.0.0';
374+
if (!isset($data['require']['composer/installers']))
375+
{
376+
$installers_version = '~1.0';
377+
if (isset($data['require']['phpbb/phpbb']) && $this->requires_phpbb_4_or_higher($data['require']['phpbb/phpbb']))
378+
{
379+
$installers_version = '^1.0 || ^2.0';
380+
}
381+
$data['require']['composer/installers'] = $installers_version;
382+
}
375383

376384
return $data;
377385
}
@@ -387,6 +395,27 @@ protected function is_stable_version($version)
387395
return preg_match('#^\d+\.\d+\.\d+(-pl\d+)?$#i', $version) === 1 && phpbb_version_compare($version, '1.0.0', '>=');
388396
}
389397

398+
/**
399+
* Check if phpBB requirement allows 4.0.0 or higher
400+
*
401+
* @param string $constraint Version constraint
402+
* @return bool True if constraint allows phpBB 4.0.0+
403+
*/
404+
protected function requires_phpbb_4_or_higher($constraint)
405+
{
406+
try
407+
{
408+
$parser = new \Composer\Semver\VersionParser();
409+
$constraintObj = $parser->parseConstraints($constraint);
410+
// Check if the constraint excludes versions below 4.0.0 by testing if 3.9.9 does NOT satisfy the constraint
411+
return !$constraintObj->matches(new \Composer\Semver\Constraint\Constraint('==', '3.9.9.0'));
412+
}
413+
catch (\Exception $e)
414+
{
415+
return false;
416+
}
417+
}
418+
390419
/**
391420
* Get prevalidator
392421
*

0 commit comments

Comments
 (0)