Separate configuration paths for Cli_Project and Web_Project (same application)
A week ago I had an issue when I wanted to load the configurations for my Cli_Project from a different configuration path than config/
I wanted the application to work this way, because my CLI commands do not require a request object for example, or ACL, and probably lost of other components in the future as I develop it.
Looking inside composer.json you will find found this line:
"Aura\\Web_Project\\_Config\\": "config/"
So the trivial thing to do was adding another configuration similar to this:
"Aura\\Cli_Project\\_Config\\": "config/cli/"
This did not work well for me, and Cli_Project was still loading Common from config/
Than Harikt send me couple of links on IRC, leading me making another change in composer.json, finally it was looking like this:
"autoload": {
"psr-4": {
"": "src/",
"Aura\\Framework_Project\\_Config\\": "config/",
"Aura\\Cli_Project\\_Config\\": "config/cli/",
"Aura\\Web_Project\\_Config\\": "config/web/",
}
},
"extra": {
"aura": {
"type": "project",
"config": {
"common": [
"Aura\\Framework_Project\\_Config\\Common",
"Aura\\Cli_Project\\_Config\\Common",
"Aura\\Web_Project\\_Config\\Common"
],
"dev": [
"Aura\\Framework_Project\\_Config\\Dev",
"Aura\\Cli_Project\\_Config\\Dev",
"Aura\\Web_Project\\_Config\\Dev"
],
"test": [
"Aura\\Framework_Project\\_Config\\Test",
"Aura\\Cli_Project\\_Config\\Test",
"Aura\\Web_Project\\_Config\\Test"
],
"prod": [
"Aura\\Framework_Project\\_Config\\Prod",
"Aura\\Cli_Project\\_Config\\Prod",
"Aura\\Web_Project\\_Config\\Prod"
]
}
}
}
Notice the "config" property, all it's child properties (common,dev,test,prod) can receive an array instead of a string.
Allowing to supply multiple configuration paths per type.
In this manner, framework configuration loads first, then other configurations.
I still have one issue with this method, had to add this lines to _env.php, web/Common.php, cli/Common.php:
_env.php
$_ENV['AURA_SAPI_NAME'] = php_sapi_name();
web/Common.php
public function define(Container $di) {
if($_ENV['AURA_SAPI_NAME'] === 'cli') {
return;
}
...
}
public function modify(Container $di) {
if($_ENV['AURA_SAPI_NAME'] === 'cli') {
return;
}
...
}
cli/Common.php
public function define(Container $di) {
if($_ENV['AURA_SAPI_NAME'] !== 'cli') {
return;
}
...
}
public function modify(Container $di)
{
if($_ENV['AURA_SAPI_NAME'] !== 'cli') {
return;
}
...
}
Did this because I couldn't make so the web/* configurations would not load at all, when in CLI mode.
If anyone have solution post!