DetailviewExtensionHook: provide the concrete implementation's module
refs #2949
This commit is contained in:
parent
316b998ef7
commit
c2ee3bef06
library/Icinga/Application
modules/monitoring/library/Monitoring/Hook
|
@ -174,7 +174,7 @@ class ClassLoader
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function extractModuleName($class)
|
public static function extractModuleName($class)
|
||||||
{
|
{
|
||||||
return lcfirst(
|
return lcfirst(
|
||||||
substr(
|
substr(
|
||||||
|
@ -194,7 +194,7 @@ class ClassLoader
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
protected function classBelongsToModule($class)
|
public static function classBelongsToModule($class)
|
||||||
{
|
{
|
||||||
return substr($class, 0, self::MODULE_PREFIX_LENGTH) === self::MODULE_PREFIX;
|
return substr($class, 0, self::MODULE_PREFIX_LENGTH) === self::MODULE_PREFIX;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
|
|
||||||
namespace Icinga\Module\Monitoring\Hook;
|
namespace Icinga\Module\Monitoring\Hook;
|
||||||
|
|
||||||
|
use Icinga\Application\ClassLoader;
|
||||||
|
use Icinga\Application\Icinga;
|
||||||
|
use Icinga\Application\Modules\Module;
|
||||||
use Icinga\Module\Monitoring\Object\MonitoredObject;
|
use Icinga\Module\Monitoring\Object\MonitoredObject;
|
||||||
use Icinga\Web\View;
|
use Icinga\Web\View;
|
||||||
|
|
||||||
|
@ -20,6 +23,13 @@ abstract class DetailviewExtensionHook
|
||||||
*/
|
*/
|
||||||
private $view;
|
private $view;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The module of the derived class
|
||||||
|
*
|
||||||
|
* @var Module
|
||||||
|
*/
|
||||||
|
private $module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new hook
|
* Create a new hook
|
||||||
*
|
*
|
||||||
|
@ -68,4 +78,35 @@ abstract class DetailviewExtensionHook
|
||||||
$this->view = $view;
|
$this->view = $view;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the module of the derived class
|
||||||
|
*
|
||||||
|
* @return Module
|
||||||
|
*/
|
||||||
|
public function getModule()
|
||||||
|
{
|
||||||
|
if ($this->module === null) {
|
||||||
|
$class = get_class($this);
|
||||||
|
if (ClassLoader::classBelongsToModule($class)) {
|
||||||
|
$this->module = Icinga::app()->getModuleManager()->getModule(ClassLoader::extractModuleName($class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->module;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the module of the derived class
|
||||||
|
*
|
||||||
|
* @param Module $module
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setModule(Module $module)
|
||||||
|
{
|
||||||
|
$this->module = $module;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue