php 如何指定 Composer 安装路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11883374/
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 specify Composer install path?
提问by Tower
I have this definition:
我有这个定义:
{
"repositories": [
{
"type": "package",
"package": {
"name": "symfony/sfGuardPlugin",
"version": "4.0.2",
"dist": {
"url": "http://plugins.symfony-project.org/get/sfGuardPlugin/sfGuardPlugin-4.0.2.tgz",
"type": "tar"
}
}
}
],
"require": {
"symfony/sfGuardPlugin": "4.0.*"
}
}
I am using Symfony 1, and I'd like to install them on plugins/sfGuardPlugin/. How do I specify this?
我正在使用 Symfony 1,我想将它们安装在plugins/sfGuardPlugin/. 我该如何指定?
回答by j0k
It seems that you can define the vendordir to be something else(pluginsin your case):
似乎您可以将vendordir定义为其他内容(plugins在您的情况下):
{
"config": {
"vendor-dir": "plugins"
}
}
Then, you might rename the package name to not have a level dir inside, like:
然后,您可以重命名包名称以使其内部没有级别目录,例如:
"package": {
"name": "sfGuardPlugin",
So, your composer.jsonshould look like this:
所以,你composer.json应该是这样的:
{
"config": {
"vendor-dir": "plugins"
},
"repositories": [
{
"type": "package",
"package": {
"name": "sfGuardPlugin",
"version": "4.0.2",
"dist": {
"url": "http://plugins.symfony-project.org/get/sfGuardPlugin/sfGuardPlugin-4.0.2.tgz",
"type": "tar"
}
}
}
],
"require": {
"sfGuardPlugin": "4.0.*"
}
}
Edit
编辑
Using this configuration, you will get the path (which is of coursenot good for symfony):
使用这个配置,你会得到路径(这对symfony当然不好):
plugins/sfGuardPlugin/sfGuardPlugin-4.0.2/
插件/sfGuardPlugin/sfGuardPlugin-4.0.2/
I found a workaround with this composer.json:
我找到了一个解决方法composer.json:
{
"config": {
"vendor-dir": "plugins"
},
"repositories": [
{
"type": "package",
"package": {
"name": "sfGuardPlugin",
"version": "4.0.2",
"source": {
"url": "http://svn.symfony-project.com/plugins/sfGuardPlugin/",
"type": "svn",
"reference": "branches/1.3/"
}
}
}
],
"require": {
"sfGuardPlugin": "4.0.*"
}
}
回答by Adam V.
You can also use composer/installers, a multi-framework composer library installer with the "symfony1-plugin" package type. This is what my composer.json file looks like, in order for it to install both Symfony 1.4 (in lib/vendor) and plugins in (/plugins):
您还可以使用composer/installers,这是一个多框架 Composer 库安装程序,具有“symfony1-plugin”包类型。这是我的 composer.json 文件的样子,以便它安装 Symfony 1.4(在 lib/vendor 中)和插件(/plugins):
{
"config": {
"vendor-dir": "lib/vendor"
},
"repositories": {
"symfony": {
"type": "package",
"package": {
"name": "symfony/symfony1",
"version": "1.4",
"dist": {
"url": "https://github.com/symfony/symfony1/zipball/1.4",
"type": "zip"
}
}
},
"sfResquePlugin" : {
"type": "package",
"package": {
"name": "devpips/sfResquePlugin",
"type": "symfony1-plugin",
"version": "0.1",
"dist": {
"url": "https://github.com/devpips/sfResquePlugin/zipball/master",
"type": "zip"
}
}
}
},
"require": {
"composer/installers": "dev-master",
"symfony/symfony1": "1.4",
"devpips/sfResquePlugin":"0.1"
}
}
回答by GabLeRoux
See COMPOSER_VENDOR_DIRenvironment variable.
请参阅COMPOSER_VENDOR_DIR环境变量。
By setting this var you can make Composer install the dependencies into a directory other than vendor.
通过设置此变量,您可以让 Composer 将依赖项安装到供应商以外的目录中。
Can be helpful in the case you want to override this in a particular environment such as vagrant or docker where you wouldn't want this to be in a shared folder / volume.
如果您想在特定环境(例如 vagrant 或 docker)中覆盖它,而您不希望它位于共享文件夹/卷中,则可能会有所帮助。
And as J0k said, there's vendor-dirin configsection of composer.json
而作为J0k说,有vendor-dir在config第composer.json
Defaults to vendor. You can install dependencies into a different directory if you want to. $HOME and ~ will be replaced by your home directory's path in vendor-dir and all *-dir options below.
默认为供应商。如果需要,您可以将依赖项安装到不同的目录中。$HOME 和 ~ 将替换为您在 vendor-dir 中的主目录路径以及下面的所有 *-dir 选项。

