Using composer to require private repos

时间:2015-07-28 15:54:55

标签: composer-php

I've probably misunderstood the docs (https://getcomposer.org) but is it possible to optimise the syntax for composer when including private repos. Ultimately; I want to step away from listing every repository and vendor pair when the vendor is the same...

In my projects composer.json I've got:

"repositories": [{
     "type": "vcs",
     "url": "git@bitbucket.org:{vendor}/{repo1}.git"
},{
     "type": "vcs",
     "url": "git@bitbucket.org:{vendor}/{repo2}.git"
},{
     "type": "vcs",
     "url": "git@bitbucket.org:{vendor}/{repo3}.git"
}]
...
"require": {
     "{vendor}/{repo1}": "dev-master",
     "{vendor}/{repo2}": "dev-master",
     "{vendor}/{repo3}": "dev-master"
 }

I figured; as the repositories is an array, then composer would search the repositories for a vendor/repo pair (or something) or if the vendor matches the vendor part of the repository url. It seems syntax heavy for a slight change...

But now I've confused myself by looking at package.json examples :s

Any kicks in the right direction would be great!

1 个答案:

答案 0 :(得分:1)

存储库不必在每个分支或标记中具有相同的vendor/package名称 - 名称可以更改。因此,添加存储库只会扩展Composer对现有软件包的知识量,而在require中添加软件包名称会明确指出它们位于何处。

如果您使用的私有存储库不止一个,我强烈建议您使用“Packagist”,“Satis”或“Toran Proxy”创建类似packagist的存储库。这样,您只需将一个repo添加到所有composer.json个文件中(不要在所有地方重复所有私人存储库)和您要使用的包。这大大减少了您感觉到的冗余,因为您只需处理所有软件包名称,以及中央存储库解决方案配置文件中的私有存储库位置。