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 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3