PHP Composer,命令行 (CLI) 添加 class 路径以自动加载 PSR-4 / PSR-0 / composer.json 中的文件
PHP Composer, command line (CLI) to add a class path to autoload PSR-4 / PSR-0 / file in composer.json
Composer 是否有任何来自 CLI 的命令可以添加到 composer.json 这样的条目?
{
"autoload": {
"psr-4": {
"Monolog\": "src/",
"Vendor\Namespace\": ""
}
}
}
并添加:
{
"autoload": {
"psr-0": {
"Monolog\": "src/",
"Vendor\Namespace\": "src/",
"Vendor_Namespace_": "src/"
}
}
}
还有这个
{
"autoload": {
"classmap": ["src/", "lib/", "Something.php"]
}
}
还有这个:
{
"autoload": {
"files": ["src/MyLibrary/functions.php"]
}
}
我看了这里:
Composer Command Line Documentation
但没有找到任何专用命令。也许有一个变通命令,如:
composer add-entry <key> <value>
或
composer set-key <key> <value>
但我不知道,
你知道吗?
不幸的是没有。至少在v1.8.4中,我也想要这个功能。
我认为最接近的命令是 config
。
$ composer config bin-dir bin/
$ composer config repositories.github.com '{"type": "vcs", "url": "https://github.com/[YOUR]/[REPO]", "//url": "https://github.com/[YOUR]/[REPO].git"}'
因为这将在 composer.json
中添加以下内容:
"config": {
"bin-dir": "bin/"
},
"repositories": {
"github.com": {
"type": "vcs",
"url": "https://github.com/[YOUR]/[REPO]",
"//url": "https://github.com/[YOUR]/[REPO].git"
}
}
不过,这个命令似乎只对“config
”和“repositories
”键有效。
然后我发现了一个关于这个主题的问题。好像社区不会添加这个功能。
Yup I don't think we really want to offer this from CLI it's gonna be a bunch of code for very limited use as typically this is done once on package creation.
- From: Issue #3398
Composer 是否有任何来自 CLI 的命令可以添加到 composer.json 这样的条目?
{
"autoload": {
"psr-4": {
"Monolog\": "src/",
"Vendor\Namespace\": ""
}
}
}
并添加:
{
"autoload": {
"psr-0": {
"Monolog\": "src/",
"Vendor\Namespace\": "src/",
"Vendor_Namespace_": "src/"
}
}
}
还有这个
{
"autoload": {
"classmap": ["src/", "lib/", "Something.php"]
}
}
还有这个:
{
"autoload": {
"files": ["src/MyLibrary/functions.php"]
}
}
我看了这里: Composer Command Line Documentation
但没有找到任何专用命令。也许有一个变通命令,如:
composer add-entry <key> <value>
或
composer set-key <key> <value>
但我不知道, 你知道吗?
不幸的是没有。至少在v1.8.4中,我也想要这个功能。
我认为最接近的命令是 config
。
$ composer config bin-dir bin/
$ composer config repositories.github.com '{"type": "vcs", "url": "https://github.com/[YOUR]/[REPO]", "//url": "https://github.com/[YOUR]/[REPO].git"}'
因为这将在 composer.json
中添加以下内容:
"config": {
"bin-dir": "bin/"
},
"repositories": {
"github.com": {
"type": "vcs",
"url": "https://github.com/[YOUR]/[REPO]",
"//url": "https://github.com/[YOUR]/[REPO].git"
}
}
不过,这个命令似乎只对“config
”和“repositories
”键有效。
然后我发现了一个关于这个主题的问题。好像社区不会添加这个功能。
Yup I don't think we really want to offer this from CLI it's gonna be a bunch of code for very limited use as typically this is done once on package creation.
- From: Issue #3398