2014-06-22 12:03:37 +02:00
|
|
|
<?php
|
2016-02-08 15:41:00 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013 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;
|
2015-07-23 12:51:10 +02:00
|
|
|
use Icinga\Application\Modules\Manager;
|
2015-08-19 13:39:37 +02:00
|
|
|
use Icinga\Application\Modules\Module;
|
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
|
|
|
/**
|
|
|
|
* (non-PHPDoc)
|
|
|
|
* @see \Icinga\Web\Controller\ActionController For the method documentation.
|
|
|
|
*/
|
|
|
|
protected function prepareInit()
|
|
|
|
{
|
2014-06-22 13:54:02 +02:00
|
|
|
$this->moduleInit();
|
2015-08-19 13:39:37 +02:00
|
|
|
if ($this->getFrontController()->getDefaultModule() !== $this->getModuleName()) {
|
|
|
|
$this->assertPermission(Manager::MODULE_PERMISSION_NS . $this->getModuleName());
|
2015-07-24 15:11:21 +02:00
|
|
|
}
|
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) {
|
2015-08-19 13:39:37 +02:00
|
|
|
$this->config = Config::module($this->getModuleName());
|
2014-06-22 12:03:37 +02:00
|
|
|
}
|
|
|
|
return $this->config;
|
|
|
|
} else {
|
|
|
|
if (! array_key_exists($file, $this->configs)) {
|
2015-08-19 13:39:37 +02:00
|
|
|
$this->configs[$file] = Config::module($this->getModuleName(), $file);
|
2014-06-22 12:03:37 +02:00
|
|
|
}
|
|
|
|
return $this->configs[$file];
|
|
|
|
}
|
|
|
|
}
|
2014-06-22 13:54:02 +02:00
|
|
|
|
2015-08-19 13:39:37 +02:00
|
|
|
/**
|
|
|
|
* Return this controller's module
|
|
|
|
*
|
|
|
|
* @return Module
|
|
|
|
*/
|
2014-06-24 20:54:39 +02:00
|
|
|
public function Module()
|
|
|
|
{
|
|
|
|
if ($this->module === null) {
|
2015-08-19 13:39:37 +02:00
|
|
|
$this->module = Icinga::app()->getModuleManager()->getModule($this->getModuleName());
|
2014-06-24 20:54:39 +02:00
|
|
|
}
|
2015-08-19 13:39:37 +02:00
|
|
|
|
2014-06-24 20:54:39 +02:00
|
|
|
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();
|
2015-08-19 13:39:37 +02:00
|
|
|
$this->getResponse()->setHeader('X-Icinga-Module', $this->getModuleName(), true);
|
2014-06-22 13:54:02 +02:00
|
|
|
}
|
2014-06-22 12:03:37 +02:00
|
|
|
}
|