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


    • 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)


    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 思科校园网的组建,sos!
  • ¥15 主要进行描述非满管状态下,管路的摩阻系数是怎么变化的,在管路长度方向上是怎么分布的(标签-matlab)
  • ¥15 multisim设计求解如图
  • ¥15 动态多目标优化,求解定义的问题的POF和POS公式
  • ¥30 实验 :UML2.0 行为建模
  • ¥15 设计一种优化调度算法并结合论文中的案例给出调度计划
  • ¥15 py文件打包exe报错TypeError:expected str,bytes or os.PathLike object,not_io.BytesIO
  • ¥15 Java编写学籍信息管理系统
  • ¥15 IPXE网刻客户机找不到服务端
  • ¥15 小贝360-4 配二个 华772S 设置WⅰFi5G 连接