mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-24 06:14:25 +02:00
Cli\Command: provide Config()
This makes it feel more like action controllers fixes #6954
This commit is contained in:
parent
f67d273bbd
commit
a38d71f17c
@ -7,6 +7,7 @@ namespace Icinga\Cli;
|
|||||||
use Icinga\Cli\Screen;
|
use Icinga\Cli\Screen;
|
||||||
use Icinga\Util\Translator;
|
use Icinga\Util\Translator;
|
||||||
use Icinga\Cli\Params;
|
use Icinga\Cli\Params;
|
||||||
|
use Icinga\Application\Config;
|
||||||
use Icinga\Application\ApplicationBootstrap as App;
|
use Icinga\Application\ApplicationBootstrap as App;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
@ -23,6 +24,10 @@ abstract class Command
|
|||||||
protected $commandName;
|
protected $commandName;
|
||||||
protected $actionName;
|
protected $actionName;
|
||||||
|
|
||||||
|
private $config;
|
||||||
|
|
||||||
|
private $configs;
|
||||||
|
|
||||||
protected $defaultActionName = 'default';
|
protected $defaultActionName = 'default';
|
||||||
|
|
||||||
public function __construct(App $app, $moduleName, $commandName, $actionName, $initialize = true)
|
public function __construct(App $app, $moduleName, $commandName, $actionName, $initialize = true)
|
||||||
@ -41,6 +46,51 @@ abstract class Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function Config($file = null)
|
||||||
|
{
|
||||||
|
if ($this->isModule()) {
|
||||||
|
return $this->getModuleConfig($file);
|
||||||
|
} else {
|
||||||
|
return $this->getMainConfig($file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getModuleConfig($file = null)
|
||||||
|
{
|
||||||
|
if ($file === null) {
|
||||||
|
if ($this->config === null) {
|
||||||
|
$this->config = Config::module($this->moduleName);
|
||||||
|
}
|
||||||
|
return $this->config;
|
||||||
|
} else {
|
||||||
|
if (! array_key_exists($file, $this->configs)) {
|
||||||
|
$this->configs[$file] = Config::module($this->moduleName, $file);
|
||||||
|
}
|
||||||
|
return $this->configs[$file];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getMainConfig($file = null)
|
||||||
|
{
|
||||||
|
if ($file === null) {
|
||||||
|
if ($this->config === null) {
|
||||||
|
$this->config = Config::app();
|
||||||
|
}
|
||||||
|
return $this->config;
|
||||||
|
} else {
|
||||||
|
if (! array_key_exists($file, $this->configs)) {
|
||||||
|
$this->configs[$file] = Config::module($module, $file);
|
||||||
|
}
|
||||||
|
return $this->configs[$file];
|
||||||
|
}
|
||||||
|
return $this->config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isModule()
|
||||||
|
{
|
||||||
|
return substr(get_class($this), 0, 14) === 'Icinga\\Module\\';
|
||||||
|
}
|
||||||
|
|
||||||
public function setParams(Params $params)
|
public function setParams(Params $params)
|
||||||
{
|
{
|
||||||
$this->params = $params;
|
$this->params = $params;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user