dqkx69935 2016-10-28 09:29 采纳率: 100%
浏览 50
已采纳

在PHP Composer中,配置依赖项以安装仍与当前平台或框架兼容的最新版本的软件包

Imagine there is some framework X and modules A and B developed for this framework. Also, A depends on B (any version of B allowed). Originally, A v.10 and B v1.0 were developed for X v1.0.

B and A are released new versions periodically. This will lead to when I update A, B would also get updated. Let's assume a few years passed and now in our repository there is A of v3.0 and B of v6.0 (and both A and B are still for X v1.0).

Now we have some local installation which have remained in the original state (X, A and B are all of v1.0). So if I updated A at this point, this would end up in updating A to v3.0 and B to v6.0. But let's assume I didn't run this update before X v2.0 release.

Now framework X v2.0 gets released and it's not compatible with X v1.0. Vendor of B then released B v7.0 for X v2.0. Vendor of A, however, hasn't updated it for X v2.0 yet. The attempt to update A to v3.0 will lead to an attempt to update B to v7.0 which won't work and the upgrade procedure will be terminated.

What I wanted would be that updating A to 3.0 will lead to updating B to v6.0 as it was the last compatible version for X v1.0.

If in A there was dependency "B 1.x", this would protect me from getting issues when B v2.0 for X v2.0 comes out. However, I won't be able to get updates to B when it gets new major releases which can still be compatible with X v1.0. This means the module vendor cannot make v2.0 if it still runs on X v1.0 framework, all updates to B must be v1.x.

So I'd better have freedom to set versions to modules (incl. major versions) independently of X framework versions. I need mechanism to resolve dependencies in the way that the most recent version of dependency gets installed ONLY if it's compatible with the current environment. If it's not compatible, the most recent compatible version will be selected instead of stopping the whole process.

It is possible to "tell" Composer "Update to the latest versions which are possible under the current conditions" instead simply of "Update to the latest versions"?

  • 写回答

1条回答 默认 最新

  • dongyan2469 2016-10-28 09:47
    关注

    First of all need to understand versioning semantic. In few words:

    version: X.Y.Z

    where:

    • X: major version (breaking changes)
    • Y: minor version (features adding, must be compatible with previous versions in the same major version)
    • Z: bug fixes (must be compatible with previous versions in the same major version)

    https://getcomposer.org/doc/articles/versions.md

    So if you write:

    for example: ^1.2.3

    it will update library to the latest including new feature (e.g: 1.*.*) (but it will keep the same major version, e.g if available it will update to 1.4.5)

    ~1.2.3 is more strict and it will update only bug fixes version (e.g: 1.2.*)

    but, unfortunately not all libraries follow version semantic, so anyway you have to check update result.

    But in both cases minimal required version is: 1.2.3

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵