Web\Controller: re-introduce ModuleActionController
This will help getting rid of a couple of if/else constructs
This commit is contained in:
parent
469eb3dc98
commit
373e1c5ecb
|
@ -86,24 +86,18 @@ class ActionController extends Zend_Controller_Action
|
|||
|
||||
protected $params;
|
||||
|
||||
// TODO: This would look better if we had a ModuleActionController
|
||||
public function Config($file = null)
|
||||
{
|
||||
if ($file === null) {
|
||||
if ($this->config === null) {
|
||||
$module = $this->getRequest()->getModuleName();
|
||||
if ($module === 'default') {
|
||||
if ($file === null) {
|
||||
$this->config = Config::app();
|
||||
} else {
|
||||
$this->config = Config::app($file);
|
||||
}
|
||||
return $this->config;
|
||||
} else {
|
||||
if ($file === null) {
|
||||
$this->config = Config::module($module);
|
||||
} else {
|
||||
$this->config = Config::module($module, $file);
|
||||
}
|
||||
if (! array_key_exists($file, $this->configs)) {
|
||||
$this->configs[$file] = Config::module($module, $file);
|
||||
}
|
||||
return $this->configs[$file];
|
||||
}
|
||||
return $this->config;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Web\Controller;
|
||||
|
||||
class ModuleActionController extends ActionController
|
||||
{
|
||||
private $config;
|
||||
|
||||
private $configs = array();
|
||||
|
||||
public function Config($file = null)
|
||||
{
|
||||
$module = $this->getRequest()->getModuleName();
|
||||
|
||||
$this->moduleName = $module;
|
||||
|
||||
if ($tile === null) {
|
||||
if ($this->config === null) {
|
||||
$this->config = Config::module($module);
|
||||
}
|
||||
return $this->config;
|
||||
} else {
|
||||
if (! array_key_exists($file, $this->configs)) {
|
||||
$this->configs[$file] = Config::module($module, $file);
|
||||
}
|
||||
return $this->configs[$file];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue