2014-06-22 12:03:37 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-06-22 12:03:37 +02:00
|
|
|
|
|
|
|
namespace Icinga\Web\Controller;
|
|
|
|
|
2014-06-22 19:39:54 +02:00
|
|
|
use Icinga\Application\Config;
|
2014-06-24 20:54:39 +02:00
|
|
|
use Icinga\Application\Icinga;
|
2014-06-22 13:49:21 +02:00
|
|
|
|
2014-09-16 09:29:03 +02:00
|
|
|
/**
|
|
|
|
* Base class for module action controllers
|
|
|
|
*/
|
2014-06-22 12:03:37 +02:00
|
|
|
class ModuleActionController extends ActionController
|
|
|
|
{
|
|
|
|
private $config;
|
|
|
|
|
|
|
|
private $configs = array();
|
|
|
|
|
2014-06-24 20:54:39 +02:00
|
|
|
private $module;
|
|
|
|
|
2014-09-16 09:29:03 +02:00
|
|
|
/**
|
|
|
|
* Module name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2014-06-22 13:49:21 +02:00
|
|
|
protected $moduleName;
|
|
|
|
|
2014-09-16 09:29:03 +02:00
|
|
|
/**
|
|
|
|
* (non-PHPDoc)
|
|
|
|
* @see \Icinga\Web\Controller\ActionController For the method documentation.
|
|
|
|
*/
|
|
|
|
protected function prepareInit()
|
|
|
|
{
|
|
|
|
$this->moduleName = $this->_request->getModuleName();
|
2014-07-04 12:33:49 +02:00
|
|
|
$this->_helper->layout()->moduleName = $this->moduleName;
|
2014-06-22 13:49:21 +02:00
|
|
|
$this->view->translationDomain = $this->moduleName;
|
2014-06-22 13:54:02 +02:00
|
|
|
$this->moduleInit();
|
2014-06-22 13:49:21 +02:00
|
|
|
}
|
|
|
|
|
2014-09-16 09:29:03 +02:00
|
|
|
/**
|
|
|
|
* Prepare module action controller initialization
|
|
|
|
*/
|
|
|
|
protected function moduleInit()
|
2014-06-22 12:03:37 +02:00
|
|
|
{
|
2014-09-16 09:29:03 +02:00
|
|
|
}
|
2014-06-22 12:03:37 +02:00
|
|
|
|
2014-09-16 09:29:03 +02:00
|
|
|
public function Config($file = null)
|
|
|
|
{
|
2014-06-22 19:39:54 +02:00
|
|
|
if ($file === null) {
|
2014-06-22 12:03:37 +02:00
|
|
|
if ($this->config === null) {
|
2014-09-16 09:29:03 +02:00
|
|
|
$this->config = Config::module($this->moduleName);
|
2014-06-22 12:03:37 +02:00
|
|
|
}
|
|
|
|
return $this->config;
|
|
|
|
} else {
|
|
|
|
if (! array_key_exists($file, $this->configs)) {
|
2014-09-16 09:29:03 +02:00
|
|
|
$this->configs[$file] = Config::module($this->moduleName, $file);
|
2014-06-22 12:03:37 +02:00
|
|
|
}
|
|
|
|
return $this->configs[$file];
|
|
|
|
}
|
|
|
|
}
|
2014-06-22 13:54:02 +02:00
|
|
|
|
2014-06-24 20:54:39 +02:00
|
|
|
public function Module()
|
|
|
|
{
|
|
|
|
if ($this->module === null) {
|
|
|
|
$this->module = Icinga::app()->getModuleManager()->getModule($this->moduleName);
|
|
|
|
}
|
|
|
|
return $this->module;
|
|
|
|
}
|
|
|
|
|
2014-09-16 09:29:03 +02:00
|
|
|
/**
|
|
|
|
* (non-PHPDoc)
|
|
|
|
* @see \Icinga\Web\Controller\ActionController::postDispatchXhr() For the method documentation.
|
|
|
|
*/
|
|
|
|
public function postDispatchXhr()
|
2014-06-22 13:54:02 +02:00
|
|
|
{
|
2014-09-16 09:29:03 +02:00
|
|
|
parent::postDispatchXhr();
|
|
|
|
$this->getResponse()->setHeader('X-Icinga-Module', $this->moduleName);
|
2014-06-22 13:54:02 +02:00
|
|
|
}
|
2014-06-22 12:03:37 +02:00
|
|
|
}
|