How to constraint compatibility with PHP without explicitly constraint all the depending packages

我只是一个虾纸丫 提交于 2020-01-25 09:20:30

问题


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:

  1. 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
    
  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!