问题
I got this requirement in my composer.json
:
"php": ">= 5.6",
"symfony/http-foundation": "^3.0"
The problem with that configuration is that it will install paragonie/random_compat
v9.99.99 which is only compatible with PHP 7 and more. But the thing is that I don't want my composer.lock
file to require PHP 7, I want it to still be compatible with PHP 5.6.
The solution I found is to track down which package was pulling this dependency and, once I found it, I added this to my requirements:
"paragonie/random_compat": "~2.0"
But I wonder if there is not a better way of doing that: somehow telling that I accept all the versions above PHP 5.6, but I don't accept packages that would force to have PHP 7?
回答1:
If you want to make composer.lock
compatible with PHP 5.6, you have at least two options to achieve that:
Use PHP 5.6 for
composer update
- you should be able to install multiple versions of PHP on your OS and run Composer like this:/path/to/php6.5 /path/to/composer update
Use platform settings in
composer.json
to force installation for specific version regardless PHP version used to run Composer commands:"config": { "platform": { "php": "5.6.38" } },
来源:https://stackoverflow.com/questions/52355467/how-to-constraint-compatibility-with-php-without-explicitly-constraint-all-the-d