php - 在 Composer 为存储库设置名称

标签 php json terminal repository composer-php

我在服务器上有我的私有(private)存储库。在我的 Composer 文件中,我有以下 JSON:

"repositories": [
    {
     "type": "composer",
     "url": "myrepositoryurl"
    }
]

一切正常。如果我运行以下命令。

composer config repositories vcs myrepositoryurl

我收到来自 composer 的错误消息:

[InvalidArgumentException]                                               
Setting repositories does not exist or is not supported by this command

如果我将命令更改为

composer config repositories.name vcs myrepositoryurl

一切正常,我在 composer.json 文件中得到了以下更新:

"repositories": {
  "name": {
    "type": "composer",
    "url": "myrepositoryurl"
  }
}

这两者之间有什么实际区别吗?如果我不想为我的存储库 url 设置名称怎么办?我可以从命令行执行此操作吗?

最佳答案

Is there any actual difference between these two?

没有。两个 JSON 元素都转换为 PHP 中的数组,因此它们是等效的,一个具有数字键,另一个具有命名键。因此,“repositories.key”的存在是为了从 CLI 中通过 key 引用 repo。

在存储库中并不真正需要它,因为您可以添加多个以逗号分隔的条目。设置“名称”仅与包相关(当它们发布时)。

仅当您想从 CLI 添加多个存储库(通过 key 名称)时才需要。

这没有记录在案,但人们时常会遇到这个问题。 引用:https://github.com/composer/composer/issues/2802

And what if I don't want to set a name to my repository url?

手动编辑 composer.json 文件。

Can I do that from the command line?

没有。从 CLI 中选择它之一

  • 配置键值
  • 配置键 value1 ... valueN(值数组)
  • 然后是config repositories.key value

不支持语法 composer config repositories vcs myrepositoryurl,参见 https://getcomposer.org/doc/03-cli.md#modifying-repositories


注意命令:composer config repositories.name vcs myrepositoryurl

具有 vcs 类型,而不是像您帖子中那样的 composer

{
    "repositories": {
        "name": {
            "type": "vcs",
            "url": "myrepositoryurl"
        }
    }
}

关于php - 在 Composer 为存储库设置名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32250385/

相关文章:

macos - Mac OS X 终端 : Run Song when Computer is Asleep?

terminal - 解析_git_dirty :11: command not found: tail

linux - 某些环境变量在某些情况下不会加载

php - jquery fadeToggle 不适用于回显脚本

c# - 如何将字符串编码成Json字符串文本?

mysql - Laravel MySQL JSON LIKE 查询

javascript - 无法在 React 中访问嵌套的 JSON 对象

php - 构建轻量级面向公众网站的工具箱/框架

php - 索引编制期间Elasticsearch MapperParsingException [无法解析,文档为空]

php - 讨厌 reCAPTCHA - CakePHP 验证码替代品?