Composer. How to install a specific version of package based on user php version?

拟墨画扇 提交于 2019-12-02 00:09:19

TL;DR: Yes.

By default, composer uses the version of the php executable to determine, which version of the package to install. This can be overridden in the config section of composer.json, for example:

"config": {
    "vendor-dir": "vendor",
    "platform": {
        "php": "5.6"
    }
 }

When someone requires your package, this version is compared to the one specified in the requirements list of your package's composer.json:

"require": {
    "php": ">=7.2.0",
}

So if, for example, version 1 of your package requires php 5.6, and version 2 requires php 7.0, someone who runs composer require your-package with php 5.6 will have version 1 installed. If someone runs it with an older version than required by any of your versions, they'll get an error stating that composer could not find a package that satisfies all the requirements, the php version being one of them.

Install only one composer you can access this composer with different php version

/usr/bin/php /usr/local/bin/composer
/usr/bin/php7.1 /usr/local/bin/composer
/usr/bin/php7.0 /usr/local/bin/composer
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!