如何在没有依赖的情况下在composer中安装包

use*_*180 2 php symfony composer-php

我使用composersymfony php.

有一个bundle A依赖于另一个bundle B v 1.1.

但我有最新版本的bundle B v 2.

现在我想安装bundle A而不安装它的依赖项bundle B v 1.1.

我该怎么办?请建议.

Nic*_*ich 6

建立:

最新的瓢虫捆绑版本,1.0.2但同时有一些更多的提交.它需要瓢虫版本,1.0.8其中不包括最新的变化.

解:

一个简单的解决方案是使用内联别名.就像是:

"require" : {
    "raulfraile/ladybug-bundle": "dev-master as 1.0.3"
    "raulfraile/ladybug": "dev-master as 1.0.9"
}
Run Code Online (Sandbox Code Playgroud)

替代方案:

您可以在composer.json中定义具有相同名称的包,其中包含已更改的依赖项.

只需从原始包中复制包定义,添加dist/source位置并编辑要求.

然后,composer将使用这个新的包定义,因为它从所有已知的存储库中选择第一个匹配(最后总是查询packagist).

您应该为dist-zip选择一个特定的提交.一个例子:

"repositories": [
    {
        "type": "package",
        "package": {
            "name": "raulfraile/ladybug-bundle",
            "version": "1.0.3",
            "require": {
               "raulfraile/ladybug" : "~1.0@dev"
            },
            "dist": {
                "url": "https://github.com/raulfraile/LadybugBundle/archive/5c3739a881313f63f7b47ace49af5deeed211362.zip",
                "type": "zip"
            },
        }
    }
],
Run Code Online (Sandbox Code Playgroud)

现在需要"raulfraile/ladybug-bundle": "~1.0"在您的composer.json中,它将使用1.0.3您自己定义的版本.