作曲家。如何根据用户php版本安装特定版本的软件包? [英] Composer. How to install a specific version of package based on user php version?

查看:58
本文介绍了作曲家。如何根据用户php版本安装特定版本的软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个版本的软件包:php7和php5。是否可以使作曲家在安装软件包时确定用户拥有哪个版本的php,并据此安装我的软件包的正确版本?

I have a two version of my package: for php7 and for php5. Is it possible to make composer determine when installing the package which version of php the user has, and depending on this, install the correct version of my package?

推荐答案

TL; DR:是。

默认情况下,composer使用php可执行文件的版本来确定要安装的软件包的版本。可以在composer.json的 config 部分中对此进行覆盖,例如:

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"
    }
 }

当某人需要您的软件包时,会将此版本与需求列表中指定的版本进行比较您的软件包的composer.json:

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",
}

因此,例如,如果您的软件包的版本1需要php 5.6 ,而版本2需要php 7.0,而运行 composer的用户需要您的软件包和php 5.6,将会安装版本1。如果有人用比您的任何一个版本都要求的版本更旧的版本运行它,他们会收到一条错误消息,指出作曲家找不到满足所有要求的软件包,而php版本就是其中之一。

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.

这篇关于作曲家。如何根据用户php版本安装特定版本的软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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