Web\Controller: re-introduce ModuleActionController

This will help getting rid of a couple of if/else constructs
This commit is contained in:
Thomas Gelf 2014-06-22 12:03:37 +02:00
parent 469eb3dc98
commit 373e1c5ecb
2 changed files with 38 additions and 15 deletions

View File

@ -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 ($this->config === null) {
$module = $this->getRequest()->getModuleName();
if ($module === 'default') {
if ($file === null) {
$this->config = Config::app();
} else {
$this->config = Config::app($file);
}
} else {
if ($file === null) {
$this->config = Config::module($module);
} else {
$this->config = Config::module($module, $file);
}
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;
}

View File

@ -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];
}
}
}