Force composer需要在版本X和版本Y之间使用PHP版本。

时间:2020-12-18 06:59:14

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

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

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

现在我们遇到了一个问题,我们做了一个“编写器更新”来获得一些外部包的最新版本。因为你的作曲家。json的样子

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

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

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

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?

是否有可能让作曲家要求在5.3.3和5.3.5之间使用PHP版本?或者最大可用版本?

I tried

我试着

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

and

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

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.

但两者都没有成功。我得到一个“请求的包php不能在任何版本中找到,可能在包名中有一个错误。”错误。

Any Ideas? Thanks in advance

什么好主意吗?谢谢提前

5 个解决方案

#1


30  

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.

我认为至少可以说,您正在开发最新的PHP,并且正在以一个非常过时的版本运行生产。这将会带来很多可能的问题,不仅因为您将丢失的安全补丁,更重要的是由于PHP的bug修复,这些补丁主要在版本5.3.9和5.3.23中被引入,这从根本上改变了一些细节的PHP行为。不讨论意外使用5.4或5.5的特性的风险。

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.

而且真的没有办法让作曲家来处理这种情况。在运行composer更新时使用的PHP版本决定了依赖项的解析,受PHP版本的影响,并安装了PHP扩展。

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).

如果您正在使用的PHP版本不符合这个版本要求,那么您不能定义一个包只应该用于5.3.3和5.3.5之间的PHP版本。由于使用的PHP版本超过了上版本限制,这样的包不符合版本要求,而且编写器报告没有找到包(不说明它已经看到了包,但是由于版本限制,它们必须被忽略)。

There are probably three obvious ways out:

有三种显而易见的方法:

  1. Downgrade your development environment to the production version you are really using. If more than one is used: The oldest one. That way any requirements for PHP versions will be matched. Run composer update then, and you are done.

    将您的开发环境降级为您真正使用的生产版本。如果使用不止一个:最老的。这样就可以匹配PHP版本的任何需求。然后运行composer更新,您就完成了。

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

    升级你的生产环境。无需进一步解释,但我不得不指出,您不仅错过了许多非常好的PHP特性,还缺少了大量的性能提升,因为PHP 5.5确实比5.3快得多。

  3. 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).

    添加一个“平台。php“配置到全局或项目的组合。json。这将告诉编写器重写PHP版本运行Composer本身,并使用不同的PHP版本计算依赖关系。作曲家配置- g平台。php 5.3.5对于全局设置(将影响所有其他的Composer运行),而没有-g用于本地设置(只会影响到该项目中的Composer操作,如果您在多个项目中开发了不同的php版本)。

#2


46  

Since the config parameter in composer.json is available. You could something like this:

由于编写器中的配置参数。json是可用的。你可以这样:

{
    "name": ".../...",
    "config": {
        "platform": {
            "php": "5.3.5"
        }
    },
    "require": {
        ...
    }
} 

https://getcomposer.org/doc/06-config.md#platform

https://getcomposer.org/doc/06-config.md平台

#3


6  

What about trying the tilde operator

试试波浪号操作符!

Tilde Operator ~1.2 Very useful for projects that follow semantic versioning. ~1.2 is equivalent to >=1.2,<2.0. For more details, read the next section below.

Tilde操作符~1.2对于遵循语义版本控制的项目非常有用。~1.2相当于>=1.2,<2.0。有关更多细节,请阅读下面的下一节。

Next Significant Release (Tilde Operator)#

下一个重要版本(Tilde操作符)#。

The ~ operator is best explained by example: ~1.2 is equivalent to

最好用实例说明~1.2等于。

=1.2,<2.0, while ~1.2.3 is equivalent to >=1.2.3,<1.3. As you can see it is mostly useful for projects respecting semantic versioning. A common usage would be to mark the minimum minor version you depend on, like ~1.2 (which allows anything up to, but not including, 2.0). Since in theory there should be no backwards compatibility breaks until 2.0, that works well. Another way of looking at it is that using ~ specifies a minimum version, but allows the last digit specified to go up.

= 1.2 < 2.0,而~ 1.2.3相当于> = 1.2.3,< 1.3。正如您所看到的,它对有关语义版本控制的项目非常有用。一个常见的用法是标记你所依赖的最小版本,比如~1.2(允许任何内容,但不包括2.0)。从理论上讲,在2.0之前不应该有向后兼容的中断,这很有效。另一种查看方法是使用~指定一个最小版本,但允许指定的最后一个数字上升。

Note: Though 2.0-beta.1 is strictly before 2.0, a version constraint like ~1.2 would not install it. As said above ~1.2 only means the .2 can change but the 1. part is fixed.

注意:尽管2.0 beta。1在2.0之前是严格的,像~1.2这样的版本约束不会安装它。正如上面所说的~1.2只意味着。2可以改变,但1。一部分是固定的。

Note: The ~ operator has an exception on its behavior for the major release number. This means for example that ~1 is the same as ~1.0 as it will not allow the major number to increase trying to keep backwards compatibility.

注意:~操作符对主版本号的行为有一个异常。这意味着~1和~1.0是一样的,因为它不允许主要的数字增加试图保持向后兼容性。

#4


2  

Try this (remove comma):

试试这个(去掉逗号):

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

#5


1  

Remove your composer.lock and vendor directory.

把你的作曲家。锁和供应商目录。

Now place platform option to composer.json

现在,将平台选项放置到组合。json。

"config": {

    "platform": {
        "php": "7.0"
    }

},

and finally, run command composer install

最后,运行命令编写器安装。

#1


30  

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.

我认为至少可以说,您正在开发最新的PHP,并且正在以一个非常过时的版本运行生产。这将会带来很多可能的问题,不仅因为您将丢失的安全补丁,更重要的是由于PHP的bug修复,这些补丁主要在版本5.3.9和5.3.23中被引入,这从根本上改变了一些细节的PHP行为。不讨论意外使用5.4或5.5的特性的风险。

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.

而且真的没有办法让作曲家来处理这种情况。在运行composer更新时使用的PHP版本决定了依赖项的解析,受PHP版本的影响,并安装了PHP扩展。

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).

如果您正在使用的PHP版本不符合这个版本要求,那么您不能定义一个包只应该用于5.3.3和5.3.5之间的PHP版本。由于使用的PHP版本超过了上版本限制,这样的包不符合版本要求,而且编写器报告没有找到包(不说明它已经看到了包,但是由于版本限制,它们必须被忽略)。

There are probably three obvious ways out:

有三种显而易见的方法:

  1. Downgrade your development environment to the production version you are really using. If more than one is used: The oldest one. That way any requirements for PHP versions will be matched. Run composer update then, and you are done.

    将您的开发环境降级为您真正使用的生产版本。如果使用不止一个:最老的。这样就可以匹配PHP版本的任何需求。然后运行composer更新,您就完成了。

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

    升级你的生产环境。无需进一步解释,但我不得不指出,您不仅错过了许多非常好的PHP特性,还缺少了大量的性能提升,因为PHP 5.5确实比5.3快得多。

  3. 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).

    添加一个“平台。php“配置到全局或项目的组合。json。这将告诉编写器重写PHP版本运行Composer本身,并使用不同的PHP版本计算依赖关系。作曲家配置- g平台。php 5.3.5对于全局设置(将影响所有其他的Composer运行),而没有-g用于本地设置(只会影响到该项目中的Composer操作,如果您在多个项目中开发了不同的php版本)。

#2


46  

Since the config parameter in composer.json is available. You could something like this:

由于编写器中的配置参数。json是可用的。你可以这样:

{
    "name": ".../...",
    "config": {
        "platform": {
            "php": "5.3.5"
        }
    },
    "require": {
        ...
    }
} 

https://getcomposer.org/doc/06-config.md#platform

https://getcomposer.org/doc/06-config.md平台

#3


6  

What about trying the tilde operator

试试波浪号操作符!

Tilde Operator ~1.2 Very useful for projects that follow semantic versioning. ~1.2 is equivalent to >=1.2,<2.0. For more details, read the next section below.

Tilde操作符~1.2对于遵循语义版本控制的项目非常有用。~1.2相当于>=1.2,<2.0。有关更多细节,请阅读下面的下一节。

Next Significant Release (Tilde Operator)#

下一个重要版本(Tilde操作符)#。

The ~ operator is best explained by example: ~1.2 is equivalent to

最好用实例说明~1.2等于。

=1.2,<2.0, while ~1.2.3 is equivalent to >=1.2.3,<1.3. As you can see it is mostly useful for projects respecting semantic versioning. A common usage would be to mark the minimum minor version you depend on, like ~1.2 (which allows anything up to, but not including, 2.0). Since in theory there should be no backwards compatibility breaks until 2.0, that works well. Another way of looking at it is that using ~ specifies a minimum version, but allows the last digit specified to go up.

= 1.2 < 2.0,而~ 1.2.3相当于> = 1.2.3,< 1.3。正如您所看到的,它对有关语义版本控制的项目非常有用。一个常见的用法是标记你所依赖的最小版本,比如~1.2(允许任何内容,但不包括2.0)。从理论上讲,在2.0之前不应该有向后兼容的中断,这很有效。另一种查看方法是使用~指定一个最小版本,但允许指定的最后一个数字上升。

Note: Though 2.0-beta.1 is strictly before 2.0, a version constraint like ~1.2 would not install it. As said above ~1.2 only means the .2 can change but the 1. part is fixed.

注意:尽管2.0 beta。1在2.0之前是严格的,像~1.2这样的版本约束不会安装它。正如上面所说的~1.2只意味着。2可以改变,但1。一部分是固定的。

Note: The ~ operator has an exception on its behavior for the major release number. This means for example that ~1 is the same as ~1.0 as it will not allow the major number to increase trying to keep backwards compatibility.

注意:~操作符对主版本号的行为有一个异常。这意味着~1和~1.0是一样的,因为它不允许主要的数字增加试图保持向后兼容性。

#4


2  

Try this (remove comma):

试试这个(去掉逗号):

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

#5


1  

Remove your composer.lock and vendor directory.

把你的作曲家。锁和供应商目录。

Now place platform option to composer.json

现在,将平台选项放置到组合。json。

"config": {

    "platform": {
        "php": "7.0"
    }

},

and finally, run command composer install

最后,运行命令编写器安装。