1
0
Fork 0

Merge pull request #8871 from Seldaek/version-selector-respect-composer-versions

Make the VersionSelector take Composer API/Runtime versions into account
pull/8874/head
Jordi Boggiano 2020-05-04 20:22:48 +02:00 committed by GitHub
commit c86c3f4516
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -15,6 +15,8 @@ namespace Composer\Package\Version;
use Composer\DependencyResolver\Pool;
use Composer\Package\BasePackage;
use Composer\Package\PackageInterface;
use Composer\Plugin\PluginInterface;
use Composer\Composer;
use Composer\Package\Loader\ArrayLoader;
use Composer\Package\Dumper\ArrayDumper;
use Composer\Semver\Constraint\Constraint;
@ -53,10 +55,14 @@ class VersionSelector
if ($targetPhpVersion) {
$phpConstraint = new Constraint('==', $this->getParser()->normalize($targetPhpVersion));
$candidates = array_filter($candidates, function ($pkg) use ($phpConstraint) {
$composerRuntimeConstraint = new Constraint('==', $this->getParser()->normalize(Composer::RUNTIME_API_VERSION));
$composerPluginConstraint = new Constraint('==', $this->getParser()->normalize(PluginInterface::PLUGIN_API_VERSION));
$candidates = array_filter($candidates, function ($pkg) use ($phpConstraint, $composerPluginConstraint, $composerRuntimeConstraint) {
$reqs = $pkg->getRequires();
return !isset($reqs['php']) || $reqs['php']->getConstraint()->matches($phpConstraint);
return (!isset($reqs['php']) || $reqs['php']->getConstraint()->matches($phpConstraint))
&& (!isset($reqs['composer-plugin-api']) || $reqs['composer-plugin-api']->getConstraint()->matches($composerPluginConstraint))
&& (!isset($reqs['composer-runtime-api']) || $reqs['composer-runtime-api']->getConstraint()->matches($composerRuntimeConstraint));
});
}