强制作曲家要求版本 X 和版本 Y 之间的 PHP 版本

Force composer to require PHP Version between Version X and Version Y(强制作曲家要求版本 X 和版本 Y 之间的 PHP 版本)
本文介绍了强制作曲家要求版本 X 和版本 Y 之间的 PHP 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在您的服务器(最高 5.3.5)和开发机器(最高 5.5.9)上运行不同的 PHP 版本.

we have a mix of different PHP versions running on your servers (max 5.3.5) and development machines (max 5.5.9).

现在我们遇到了一个问题,我们进行了composer update"以获取一些外部 Bundle 的最新版本.因为你的 composer.json 看起来像

Now we ran into the problem that we did a "composer update" to get the latest Version of some external Bundles. Since your composer.json looks like

"require": {
        "php": ">=5.3.3",
        .....
    },

我们得到了一些需要 PHP 5.5 的 Bundle.在我们的开发机器上没问题,但在服务器上:(

we get some Bundles that required PHP 5.5. No problem on our dev machines, but on the server :(

有没有可能告诉作曲家需要 5.3.3 和 5.3.5 之间的 PHP 版本?还是最大可用版本?

Is there any possibility to tell composer to require a PHP version between 5.3.3 and 5.3.5? Or a max available Version?

我试过了

"require": {
        "php": ">=5.3.3, <=5.3.5",
            .....
        },

"require": {
            "php": "<=5.3.5",
                .....
            },

但两者都没有成功.我收到在任何版本中都找不到请求的包 php,包名称可能有错别字."错误.

but both didn't work out. I get a "The requested package php could not be found in any version, there may be a typo in the package name." Error.

有什么想法吗?提前致谢

Any Ideas? Thanks in advance

推荐答案

我发现至少可以说您正在使用最新的可用 PHP 进行开发并且正在使用非常过时的版本运行生产是值得怀疑的.这会导致很多可能的问题,不仅是因为您会丢失安全补丁,更重要的是因为主要在 5.3.9 和 5.3.23 版本中引入的 PHP 错误修复改变了某些 PHP 行为细节相当基本.不谈论意外使用 5.4 或 5.5 功能的风险.

I find it questionable to say the least that you are developing with the newest PHP available and are running production with a very outdated version. There will be plenty of possible problems arising from this, not only because of security patches that you would be missing, but more importantly because of PHP bug fixes that got introduced mostly in versions 5.3.9 and 5.3.23 that changes PHP behavior in some details pretty fundamentally. Not talking about the risk of accidentally using features of 5.4 or 5.5.

而且确实没有办法让 Composer 处理这种情况.运行 composer update 时使用的 PHP 版本决定依赖项的解析,受 PHP 版本和安装的 PHP 扩展的影响.

And there really is no way to make Composer deal with this situation. The PHP version that is used when running composer update determines the resolution of dependencies, being influenced by PHP version and installed PHP extensions.

如果您用于更新的 PHP 不符合此版本要求,则您不能定义一个包只能用于 5.3.3 和 5.3.5 之间的 PHP 版本.因为使用的 PHP 版本超过了版本上限,这样的包不符合版本要求,Composer 报告没有找到包(没有告诉它已经看到包,但它们不得不被忽略,因为版本约束).

You cannot define that a package should only be used for PHP versions between 5.3.3 and 5.3.5 if the PHP you are using for the update is not matching this version requirement. Because the used PHP version exceeds the upper version constraint, such a package is not eligible for fulfilling the version requirement, and Composer reports that no package has been found (not telling that it has seen the packages, but they had to be ignored because of the version constraint).

可能有三种明显的出路:

There are probably three obvious ways out:

  1. 将您的开发环境降级到您真正使用的生产版本.如果使用多个:最旧的一个.这样,对 PHP 版本的任何要求都将匹配.然后运行composer update,就大功告成了.

升级您的生产环境.无需进一步解释,但我不得不提一下,您不仅错过了很多非常好的 PHP 功能,而且还错过了性能大幅提升,因为 PHP 5.5 确实比 5.3 快得多.

Upgrade your production environment. Needs no further explanation, but I have to mention that not only are you missing a lot of very nice PHP features, you are also missing a substantial performance increase, because PHP 5.5 is really that much faster than 5.3.

将platform.php"配置添加到全局或项目的 composer.json.这将告诉 Composer 覆盖运行 Composer 本身的 PHP 版本,而是计算与该不同 PHP 版本的依赖关系.composer config -g platform.php 5.3.5 用于全局设置(将影响所有进一步的 Composer 运行),没有 -g 用于本地设置(只会影响 Composer 操作项目,以防您在多个项目上使用不同的 PHP 生产版本进行开发).

Add a "platform.php" configuration to either the global or project's composer.json. This will tell Composer to override the PHP version running Composer itself, and instead calculate the dependencies with that different PHP version. composer config -g platform.php 5.3.5 for global setting (will affect all further Composer runs), without -g for local setting (will only affect Composer operations in that project, in case you develop on more than one project with different production versions of PHP).

这篇关于强制作曲家要求版本 X 和版本 Y 之间的 PHP 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)