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

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

问题描述

我的包有两个版本:php7 和 php5.是否可以让composer在安装包时确定用户拥有哪个版本的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,则使用 php 5.6 运行 composer require your-package 的人将安装版本 1.如果有人使用比您的任何版本要求的旧版本运行它,他们会收到一条错误消息,指出 composer 找不到满足所有要求的包,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天全站免登陆