编写器依赖约束


Composer dependency constraint

是否有可能让编写器仅在PHP版本低于给定版本时才安装包?

https://github.com/ircmaxell/password_compat

"ircmaxell/password-compat": "dev-master"

我发现这个包是有用的,因为我有一个web服务器上运行的PHP 5.4,我需要的password_*函数只有可用>= PHP 5.5。

是的,有。您可以在packagist网站上找到详细信息,但基本上,包/依赖项应该按照以下要求定义:

{
    "name": "ircmaxell/password-compat",
    "description": "A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash",
    "require": {
        "php": "<5.5.*",
        "phpunit/phpunit": "4.*"
    }
}

您可以看到,我已经将"php": "<5.5.*"添加到包的需求中。您可以将此需求添加到您自己的编写器中。json文件,通过添加依赖到您的repositories数组在编写器。Json文件,并在其中添加需求:

{
    "repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/ircmaxell/password_compat",
        "require": {
            "php": "<5.5.*",
        }
    }]
}

类似的东西,我只安装了php5.5,所以我无法测试这个,虽然…但是看完文档,我很确定这是可能的。