MrM*_*MAG 1 bash json command laravel composer-php
我正在寻找一种从命令行界面向我的Laravel项目的composer.json文件中的自动加载PSR-4-Section中添加名称空间的方法。
{
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "modules/",
/* add more here */
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望有一个类似的命令composer require,但是我没有找到这个机会的有效命令。
有没有人为此提出适当的解决方案?
即使是一个脚本bash,powershell,php,...,将不胜感激。能够从命令行运行它是主要的事情。
如果有人需要此方法,
我想出了这种方法,它对我有用。
public function handle($key, $namespace, $output = 'composer.json')
{
$file = 'composer.json';
$data = json_decode(file_get_contents($file), true);
$data["autoload"]["psr-4"][] = array($key => $namespace);
file_put_contents($output, json_encode($data, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT));
}
Run Code Online (Sandbox Code Playgroud)