DetailviewExtensionHook: provide the concrete implementation's module
refs #2949
This commit is contained in:
parent
316b998ef7
commit
c2ee3bef06
|
@ -174,7 +174,7 @@ class ClassLoader
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function extractModuleName($class)
|
||||
public static function extractModuleName($class)
|
||||
{
|
||||
return lcfirst(
|
||||
substr(
|
||||
|
@ -194,7 +194,7 @@ class ClassLoader
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function classBelongsToModule($class)
|
||||
public static function classBelongsToModule($class)
|
||||
{
|
||||
return substr($class, 0, self::MODULE_PREFIX_LENGTH) === self::MODULE_PREFIX;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
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\Web\View;
|
||||
|
||||
|
@ -20,6 +23,13 @@ abstract class DetailviewExtensionHook
|
|||
*/
|
||||
private $view;
|
||||
|
||||
/**
|
||||
* The module of the derived class
|
||||
*
|
||||
* @var Module
|
||||
*/
|
||||
private $module;
|
||||
|
||||
/**
|
||||
* Create a new hook
|
||||
*
|
||||
|
@ -68,4 +78,35 @@ abstract class DetailviewExtensionHook
|
|||
$this->view = $view;
|
||||
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