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

查看:13
本文介绍了如何在不显式约束所有依赖包的情况下约束与 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 update - 您应该能够在您的操作系统上安装多个版本的 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

  • 使用 platform 设置在 composer.json 中强制安装特定版本,而不管用于运行 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天全站免登陆