public static function load($name, Module $module = null) { if ($module === null) { $basedir = Icinga::app()->getApplicationDir('forms'); $ns = '\\Icinga\\Web\\Forms\\'; } else { $basedir = $module->getFormDir(); $ns = '\\Icinga\\Module\\' . ucfirst($module->getName()) . '\\Forms\\'; } if (preg_match('~^[a-z0-9/]+$~i', $name)) { $parts = preg_split('~/~', $name); $class = ucfirst(array_pop($parts)) . 'Form'; $file = sprintf('%s/%s/%s.php', rtrim($basedir, '/'), implode('/', $parts), $class); if (file_exists($file)) { require_once $file; $class = $ns . $class; $options = array(); if ($module !== null) { $options['icingaModule'] = $module; } return new $class($options); } } throw new ProgrammingError(sprintf('Cannot load %s (%s), no such form', $name, $file)); }
/** * Collects the tabs from the createProvidedTabs() method in the configuration controller * * If the module doesn't have the given controller or createProvidedTabs method in the controller * an empty array will be returned * * @param string $controller The name of the controller that provides tabs via createProvidedTabs * @param Module $module The module instance that provides the controller * * @return array */ private static function createModuleConfigurationTabs($controller, Module $module) { $controllerDir = $module->getControllerDir(); $name = $module->getName(); $controllerDir = $controllerDir . '/' . $controller . '.php'; $controllerName = ucfirst($name) . '_' . $controller; if (is_readable($controllerDir)) { require_once realpath($controllerDir); if (!method_exists($controllerName, "createProvidedTabs")) { return array(); } $tab = $controllerName::createProvidedTabs(); if (!is_array($tab)) { $tab = array($name => $tab); } return $tab; } return array(); }
/** * Collects the tabs from the createProvidedTabs() method in the configuration controller * * If the module doesn't have the given controller or createProvidedTabs method in the controller an empty array * will be returned * * @param string $controllerName The name of the controller that provides tabs via createProvidedTabs * @param Module $module The module instance that provides the controller * * @return array */ private static function createModuleConfigurationTabs($controllerName, Module $module) { // TODO(el): Only works for controllers w/o namepsace: https://dev.icinga.org/issues/4149 $controllerDir = $module->getControllerDir(); $name = $module->getName(); $controllerDir = $controllerDir . '/' . $controllerName . '.php'; $controllerName = ucfirst($name) . '_' . $controllerName; if (is_readable($controllerDir)) { require_once realpath($controllerDir); if (!method_exists($controllerName, 'createProvidedTabs')) { return array(); } $tab = $controllerName::createProvidedTabs(); if (!is_array($tab)) { $tab = array($name => $tab); } return $tab; } return array(); }
public function moduleAction() { $this->assertPermission('config/modules'); $app = Icinga::app(); $manager = $app->getModuleManager(); $name = $this->getParam('name'); if ($manager->hasInstalled($name)) { $this->view->moduleData = $manager->select()->from('modules')->where('name', $name)->fetchRow(); if ($manager->hasLoaded($name)) { $module = $manager->getModule($name); } else { $module = new Module($app, $name, $manager->getModuleDir($name)); } $this->view->module = $module; $this->view->tabs = $module->getConfigTabs()->activate('info'); } else { $this->view->module = false; $this->view->tabs = null; } }
/** * Try to load the module and register it in the application * * @param string $name The name of the module to load * @param mixed $basedir Optional module base directory * * @return self */ public function loadModule($name, $basedir = null) { if ($this->hasLoaded($name)) { return $this; } $module = null; if ($basedir === null) { $module = new Module($this->app, $name, $this->getModuleDir($name)); } else { $module = new Module($this->app, $name, $basedir); } $module->register(); $this->loadedModules[$name] = $module; return $this; }