如何在不显式约束所有依赖包的情况下约束与PHP的兼容性 [英] How to constraint compatibility with PHP without explicitly constraint all the depending packages

查看:63
本文介绍了如何在不显式约束所有依赖包的情况下约束与PHP的兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 composer.json 中满足了这一要求:

I got this requirement in my composer.json:

"php": ">= 5.6",
"symfony/http-foundation": "^3.0"

该配置的问题在于它将安装 paragonie / random_compat v9.99.99,该版本仅与PHP 7及更高版本兼容。但问题是我不希望我的 composer.lock 文件需要PHP 7,我希望它仍与PHP 5.6兼容。

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"

但是我不知道是否有更好的方法:以某种方式告诉我我接受PHP 5.6以上的所有版本,但我不接受会强制安装PHP 7的软件包吗?

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?

推荐答案

如果要使 composer.lock 与PHP 5.6兼容,则至少有两个选择可以实现

If you want to make composer.lock compatible with PHP 5.6, you have at least two options to achieve that:


  1. 使用PHP 5.6进行 composer更新-您应该能够在您的操作系统上安装多个版本的PHP并像这样运行Composer:

  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


  • 使用 平台 composer.json 中的a>设置,以强制安装特定版本,而与用于运行Composer命令的PHP版本无关:

  • 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"
        }
    },
    


  • 这篇关于如何在不显式约束所有依赖包的情况下约束与PHP的兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆