强制作曲家在版本X和版本Y之间要求PHP版本 [英] Force composer to require PHP Version between Version X and Version Y

查看:67
本文介绍了强制作曲家在版本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更新"以获取某些外部捆绑软件的最新版本. 由于您的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的捆绑软件.在我们的开发机上没问题,但是在服务器上:(

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开发并且正在以非常过时的版本运行生产.这样做可能会引起很多问题,这不仅是因为您将缺少安全补丁,更重要的是因为PHP漏洞修复程序主要是在5.3.9和5.3.23版本中引入的,这些漏洞在某些情况下会改变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.

向全局或项目的composer.json添加"platform.php"配置.这将告诉Composer覆盖运行Composer本身的PHP版本,而是计算具有该不同PHP版本的依赖项. composer config -g platform.php 5.3.5用于全局设置(将影响所有其他Composer运行),而-g用于本地设置(仅影响在该项目中的Composer操作,以防您使用多个不同的生产版本的PHP开发一个项目)./p>

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版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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