php 如何在 Composer 中正确要求特定提交,以便它可用于依赖包?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21314381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to correctly require a specific commit in Composer so that it would be available for dependent packages?
提问by Maciej Sz
I have a library foo/foo-libwhich requiresa specific commit from GitHub:
我有一个图书馆foo/foo-lib,其requires具体从GitHub承诺:
{
"name": "foo/foo-lib",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/KnpLabs/Gaufrette.git"
}
],
"require": {
"knplabs/gaufrette": "dev-master#2633721877cae79ad461f3ca06f3f77fb4fce02e"
}
}
and it works fine:
它工作正常:
$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Updating knplabs/gaufrette dev-master (2633721 => 2633721)
Checking out 2633721877cae79ad461f3ca06f3f77fb4fce02e
Generating autoload files
but when I require that library in other project:
但是当我在其他项目中需要该库时:
{
"name": "bar/bar-app",
"repositories": [
{
"type": "vcs",
"url": "ssh://git.example.com/foo-lib"
}
],
"require-dev": {
"foo/foo-lib": "dev-master"
}
}
it yields dependency error:
它产生依赖错误:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for foo/foo-lib dev-master -> satisfiable by foo/foo-lib[dev-master].
- foo/foo-lib dev-master requires knplabs/gaufrette dev-master#2633721877cae79ad461f3ca06f3f77fb4fce02e -> no matching package found.
So my question is: how to correctly requirethe specific commit from GitHub in my library, so that it would be available in dependent packages?
所以我的问题是:如何require在我的库中正确地从 GitHub 提交特定的提交,以便它可以在依赖包中使用?
回答by Chris
You'll have to explicitly require the Gaufrette library at that hash, with a devflag, in both your library and your application. Something like this should work in the application composer.json:
您必须dev在您的库和应用程序中明确要求该哈希中的 Gaufrette 库,并带有标志。这样的事情应该在应用程序中工作composer.json:
{
"name": "bar/bar-app",
"repositories": [
{
"type": "vcs",
"url": "ssh://git.example.com/foo-lib"
}
],
"require-dev": {
"foo/foo-lib": "dev-master",
"knplabs/gaufrette": "dev-master#2633721877cae79ad461f3ca06f3f77fb4fce02e"
}
}
From the documentation:
从文档:
If one of your dependencies has a dependency on an unstable package you need to explicitly require it as well, along with its sufficient stability flag.
如果您的依赖项之一依赖于不稳定的包,您还需要明确地要求它,以及其足够的稳定性标志。
The documentation also suggests that you'll need to include the repository for Gaufrette in your bar/bar-appComposer file, though it sounds like this wasn't necessary in this case. I'm not sure why.
该文档还建议您需要在bar/bar-appComposer 文件中包含 Gaufrette 的存储库,尽管在这种情况下听起来似乎没有必要。我不知道为什么。
回答by powpow12
Here is how you do it on the command line:
以下是在命令行上执行此操作的方法:
composer update knplabs/gaufrette:dev-master#2633721 --with-dependencies
You don't have to use the whole hash, a hash seven characters long seems to dothe trick. As mentioned above, your project will need to support dev - which it will complain about if not already set. Also, use --with-dependenciesto get any dependencies of the one you are updating.
您不必使用整个散列,七个字符长的散列似乎可以解决问题。如上所述,您的项目需要支持 dev - 如果尚未设置,它会抱怨。此外,用于--with-dependencies获取您正在更新的依赖项的任何依赖项。
回答by Gayan Kalhara
If you're making changes for a Git Repository by forking make sure that you use the The package name is actually defined in the package's own composer.json file - so even though I'd forked the package to my own joshuapaling github account, and the package was now residing at the URL https://github.com/joshuapaling/Cake-Resque.git, that had not influenced the package's name at all, from composers perspective.
如果您通过分叉对 Git 存储库进行更改,请确保您使用包名实际上是在包自己的 composer.json 文件中定义的 - 所以即使我将包分叉到我自己的 joshuapaling github 帐户,并且该包现在位于 URL https://github.com/joshuapaling/Cake-Resque.git,从作曲家的角度来看,它根本没有影响包的名称。
A stupid error - but I'm new to composer, and it wasn't clear at first! So, I hope this helps someone else with the same problem.
一个愚蠢的错误 - 但我是作曲家的新手,一开始并不清楚!所以,我希望这可以帮助其他有同样问题的人。

