CS: Fix docstrings in Icinga/Application/Modules/Module.php and Manager.php
refs #4530
This commit is contained in:
parent
d604b01349
commit
6d98b923ca
|
@ -15,9 +15,9 @@ use \Icinga\Exception\ProgrammingError;
|
|||
* Module manager that handles detecting, enabling and disabling of modules
|
||||
*
|
||||
* Modules can have 3 states:
|
||||
* - installed Means that the module exists, but could be deactivated (see enabled and loaded)
|
||||
* - enabled Means that the module is marked as being enabled and should be used
|
||||
* - loaded Means that the module has been registered in the autoloader and is being used
|
||||
* * installed, module exists but is disabled
|
||||
* * enabled, module enabled and should be loaded
|
||||
* * loaded, module enabled and loaded via the autoloader
|
||||
*
|
||||
*/
|
||||
class Manager
|
||||
|
@ -64,17 +64,15 @@ class Manager
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
private $modulePaths = array();
|
||||
private $modulePaths = array();
|
||||
|
||||
/**
|
||||
* Create a new instance of the module manager
|
||||
*
|
||||
* @param ApplicationBootstrap $app The application bootstrap. This one needs a properly defined interface
|
||||
* In order to test it correctly, the application now only requires a stdClass
|
||||
* @param string $enabledDir The path of the dir used for adding symlinks to enabled modules
|
||||
* ( must be writable )
|
||||
* @param array $availableDirs An array containing all paths where the modulemanager can look for available
|
||||
* modules
|
||||
* @param ApplicationBootstrap $app
|
||||
* @param string $enabledDir Enabled modules location. The application maintains symlinks within
|
||||
* the given path
|
||||
* @param array $availableDirs Installed modules location
|
||||
**/
|
||||
public function __construct($app, $enabledDir = null, array $availableDirs = array())
|
||||
{
|
||||
|
@ -94,14 +92,14 @@ class Manager
|
|||
/**
|
||||
* Set the module dir and checks for existence
|
||||
*
|
||||
* @param string $moduleDir The module directory to set for the module manager
|
||||
* @throws \Icinga\Exception\ProgrammingError
|
||||
* @param string $moduleDir The module directory to set for the module manager
|
||||
* @throws \Icinga\Exception\ProgrammingError
|
||||
*/
|
||||
private function prepareEssentials($moduleDir)
|
||||
{
|
||||
$this->enableDir = $moduleDir;
|
||||
|
||||
if (! file_exists($this->enableDir) || ! is_dir($this->enableDir)) {
|
||||
if (!file_exists($this->enableDir) || !is_dir($this->enableDir)) {
|
||||
throw new ProgrammingError(
|
||||
sprintf(
|
||||
'Missing module directory: %s',
|
||||
|
@ -123,8 +121,7 @@ class Manager
|
|||
}
|
||||
|
||||
/**
|
||||
* Check for enabled modules and update the internal $enabledDirs property with the enabled modules
|
||||
*
|
||||
* Check for enabled modules and update the internal $enabledDirs property with the enabled modules
|
||||
*/
|
||||
private function detectEnabledModules()
|
||||
{
|
||||
|
@ -138,7 +135,7 @@ class Manager
|
|||
}
|
||||
|
||||
$link = $this->enableDir . '/' . $file;
|
||||
if (! is_link($link)) {
|
||||
if (!is_link($link)) {
|
||||
Logger::warn(
|
||||
'Found invalid module in enabledModule directory "%s": "%s" is not a symlink',
|
||||
$this->enableDir,
|
||||
|
@ -148,7 +145,7 @@ class Manager
|
|||
}
|
||||
|
||||
$dir = realpath($link);
|
||||
if (! file_exists($dir) || ! is_dir($dir)) {
|
||||
if (!file_exists($dir) || !is_dir($dir)) {
|
||||
Logger::warn(
|
||||
'Found invalid module in enabledModule directory "%s": "%s" points to non existing path "%s"',
|
||||
$this->enableDir,
|
||||
|
@ -179,10 +176,11 @@ class Manager
|
|||
/**
|
||||
* Try to load the module and register it in the application
|
||||
*
|
||||
* @param string $name The name of the module to load
|
||||
* @param null|mixed $moduleBase An alternative class to use instead of @see Module, used for testing
|
||||
* @param string $name The name of the module to load
|
||||
* @param mixed $moduleBase Alternative class to use instead of \Icinga\Application\Modules\Module for
|
||||
* instantiating modules, used for testing
|
||||
*
|
||||
* @return self
|
||||
* @return self
|
||||
*/
|
||||
public function loadModule($name, $moduleBase = null)
|
||||
{
|
||||
|
@ -204,15 +202,15 @@ class Manager
|
|||
/**
|
||||
* Set the given module to the enabled state
|
||||
*
|
||||
* @param string $name The module to enable
|
||||
* @param string $name The module to enable
|
||||
*
|
||||
* @return self
|
||||
* @throws \Icinga\Exception\ConfigurationError When trying to enable a module that is not installed
|
||||
* @throws \Icinga\Exception\SystemPermissionException When insufficient permissions for the application exist
|
||||
* @return self
|
||||
* @throws \Icinga\Exception\ConfigurationError When trying to enable a module that is not installed
|
||||
* @throws \Icinga\Exception\SystemPermissionException When insufficient permissions for the application exist
|
||||
*/
|
||||
public function enableModule($name)
|
||||
{
|
||||
if (! $this->hasInstalled($name)) {
|
||||
if (!$this->hasInstalled($name)) {
|
||||
throw new ConfigurationError(
|
||||
sprintf(
|
||||
"Cannot enable module '%s' as it isn't installed",
|
||||
|
@ -224,7 +222,7 @@ class Manager
|
|||
clearstatcache(true);
|
||||
$target = $this->installedBaseDirs[$name];
|
||||
$link = $this->enableDir . '/' . $name;
|
||||
if (! is_writable($this->enableDir)) {
|
||||
if (!is_writable($this->enableDir)) {
|
||||
throw new SystemPermissionException(
|
||||
"Insufficient system permissions for enabling modules",
|
||||
"write",
|
||||
|
@ -247,38 +245,39 @@ class Manager
|
|||
/**
|
||||
* Disable the given module and remove it's enabled state
|
||||
*
|
||||
* @param string $name The name of the module to disable
|
||||
* @param string $name The name of the module to disable
|
||||
*
|
||||
* @return self
|
||||
* @throws \Icinga\Exception\ConfigurationError When the module is not installed or it's not symlinked
|
||||
* @throws \Icinga\Exception\SystemPermissionException When the module can't be disabled
|
||||
* @return self
|
||||
*
|
||||
* @throws \Icinga\Exception\ConfigurationError When the module is not installed or it's not symlinked
|
||||
* @throws \Icinga\Exception\SystemPermissionException When the module can't be disabled
|
||||
*/
|
||||
public function disableModule($name)
|
||||
{
|
||||
if (! $this->hasEnabled($name)) {
|
||||
if (!$this->hasEnabled($name)) {
|
||||
return $this;
|
||||
}
|
||||
if (! is_writable($this->enableDir)) {
|
||||
if (!is_writable($this->enableDir)) {
|
||||
throw new SystemPermissionException("Can't write the module directory", "write", $this->enableDir);
|
||||
return $this;
|
||||
}
|
||||
$link = $this->enableDir . '/' . $name;
|
||||
if (!file_exists($link)) {
|
||||
throw new ConfigurationError("The module $name could not be found, can't disable it");
|
||||
throw new ConfigurationError('The module ' . $name . ' could not be found, can\'t disable it');
|
||||
}
|
||||
if (!is_link($link)) {
|
||||
throw new ConfigurationError(
|
||||
"The module $name can't be disabled as this would delete the whole module. ".
|
||||
"It looks like you have installed this module manually and moved it to your module folder.".
|
||||
"In order to dynamically enable and disable modules, you have to create a symlink to ".
|
||||
"the enabled_modules folder"
|
||||
'The module ' . $name . ' can\'t be disabled as this would delete the whole module. '
|
||||
. 'It looks like you have installed this module manually and moved it to your module folder. '
|
||||
. 'In order to dynamically enable and disable modules, you have to create a symlink to '
|
||||
. 'the enabled_modules folder'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (file_exists($link) && is_link($link)) {
|
||||
if (!@unlink($link)) {
|
||||
$error = error_get_last();
|
||||
throw new SystemPermissionException($error["message"], "unlink", $link);
|
||||
throw new SystemPermissionException($error['message'], 'unlink', $link);
|
||||
}
|
||||
} else {
|
||||
|
||||
|
@ -290,11 +289,12 @@ class Manager
|
|||
/**
|
||||
* Return the directory of the given module as a string, optionally with a given sub directoy
|
||||
*
|
||||
* @param string $name The module name to return the module directory of
|
||||
* @param string $subdir The sub directory to append to the path
|
||||
* @param string $name The module name to return the module directory of
|
||||
* @param string $subdir The sub directory to append to the path
|
||||
*
|
||||
* @return string
|
||||
* @throws \Icinga\Exception\ProgrammingError When the module is not installed or existing
|
||||
* @return string
|
||||
*
|
||||
* @throws \Icinga\Exception\ProgrammingError When the module is not installed or existing
|
||||
*/
|
||||
public function getModuleDir($name, $subdir = '')
|
||||
{
|
||||
|
@ -317,8 +317,9 @@ class Manager
|
|||
/**
|
||||
* Return true when the module with the given name is installed, otherwise false
|
||||
*
|
||||
* @param string $name The module to check for being installed
|
||||
* @return bool
|
||||
* @param string $name The module to check for being installed
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasInstalled($name)
|
||||
{
|
||||
|
@ -331,9 +332,9 @@ class Manager
|
|||
/**
|
||||
* Return true when the given module is in enabled state, otherwise false
|
||||
*
|
||||
* @param string $name The module to check for being enabled
|
||||
* @param string $name The module to check for being enabled
|
||||
*
|
||||
* @return bool
|
||||
* @return bool
|
||||
*/
|
||||
public function hasEnabled($name)
|
||||
{
|
||||
|
@ -343,9 +344,9 @@ class Manager
|
|||
/**
|
||||
* Return true when the module is in loaded state, otherwise false
|
||||
*
|
||||
* @param string $name The module to check for being loaded
|
||||
* @param string $name The module to check for being loaded
|
||||
*
|
||||
* @return bool
|
||||
* @return bool
|
||||
*/
|
||||
public function hasLoaded($name)
|
||||
{
|
||||
|
@ -356,7 +357,8 @@ class Manager
|
|||
* Return an array containing all loaded modules
|
||||
*
|
||||
* @return array
|
||||
* @see Module
|
||||
*
|
||||
* @see \Icinga\Application\Modules\Module
|
||||
*/
|
||||
public function getLoadedModules()
|
||||
{
|
||||
|
@ -366,14 +368,15 @@ class Manager
|
|||
/**
|
||||
* Return the module instance of the given module when it is loaded
|
||||
*
|
||||
* @param string $name The module name to return
|
||||
* @return Module
|
||||
* @param string $name The module name to return
|
||||
*
|
||||
* @throws \Icinga\Exception\ProgrammingError Thrown when the module hasn't been loaded
|
||||
* @return \Icinga\Application\Modules\Module
|
||||
*
|
||||
* @throws \Icinga\Exception\ProgrammingError When the module hasn't been loaded
|
||||
*/
|
||||
public function getModule($name)
|
||||
{
|
||||
if (! $this->hasLoaded($name)) {
|
||||
if (!$this->hasLoaded($name)) {
|
||||
throw new ProgrammingError(
|
||||
sprintf(
|
||||
'Cannot access module %s as it hasn\'t been loaded',
|
||||
|
@ -388,22 +391,22 @@ class Manager
|
|||
* Return an array containing information objects for each available module
|
||||
*
|
||||
* Each entry has the following fields
|
||||
* - name: The name of the module as a string
|
||||
* - path: The path where the module is located as a string
|
||||
* - enabled: Whether the module is enabled or not as a boolean
|
||||
* - loaded: Whether the module is loaded or not as a boolean
|
||||
* * name, name of the module as a string
|
||||
* * path, path where the module is located as a string
|
||||
* * enabled, whether the module is enabled or not as a boolean
|
||||
* * loaded, whether the module is loaded or not as a boolean
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getModuleInfo()
|
||||
{
|
||||
$installed = $this->listInstalledModules();
|
||||
|
||||
|
||||
$info = array();
|
||||
if ($installed === null) {
|
||||
return $info;
|
||||
}
|
||||
|
||||
|
||||
foreach ($installed as $name) {
|
||||
$info[] = (object) array(
|
||||
'name' => $name,
|
||||
|
@ -438,17 +441,18 @@ class Manager
|
|||
/**
|
||||
* Return an array containing all installled module names as strings
|
||||
*
|
||||
* Calls @see Manager::detectInstalledModules if no module discovery has
|
||||
* been performed yet
|
||||
* Calls detectInstalledModules() if no module discovery has been performed yet
|
||||
*
|
||||
* @return array
|
||||
* @return array
|
||||
*
|
||||
* @see detectInstalledModules()
|
||||
*/
|
||||
public function listInstalledModules()
|
||||
{
|
||||
if ($this->installedBaseDirs === null) {
|
||||
$this->detectInstalledModules();
|
||||
}
|
||||
|
||||
|
||||
if ($this->installedBaseDirs !== null) {
|
||||
return array_keys($this->installedBaseDirs);
|
||||
}
|
||||
|
@ -466,7 +470,7 @@ class Manager
|
|||
if ($fh === false) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
while ($name = readdir($fh)) {
|
||||
if ($name[0] === '.') {
|
||||
continue;
|
||||
|
|
|
@ -43,54 +43,63 @@ class Module
|
|||
{
|
||||
/**
|
||||
* Module name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Base directory of module
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $basedir;
|
||||
|
||||
/**
|
||||
* Directory for styles
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cssdir;
|
||||
|
||||
/**
|
||||
* Library directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $libdir;
|
||||
|
||||
/**
|
||||
* Directory containing translations
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $localedir;
|
||||
|
||||
/**
|
||||
* Directory where controllers reside
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $controllerdir;
|
||||
|
||||
/**
|
||||
* Directory containing form implementations
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $formdir;
|
||||
|
||||
/**
|
||||
* Module bootstrapping script
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $registerscript;
|
||||
|
||||
/**
|
||||
* Icinga application
|
||||
*
|
||||
* @var \Icinga\Application\Web
|
||||
*/
|
||||
private $app;
|
||||
|
@ -98,9 +107,9 @@ class Module
|
|||
/**
|
||||
* Create a new module object
|
||||
*
|
||||
* @param ApplicationBootstrap $app
|
||||
* @param string $name
|
||||
* @param string $basedir
|
||||
* @param ApplicationBootstrap $app
|
||||
* @param string $name
|
||||
* @param string $basedir
|
||||
*/
|
||||
public function __construct(ApplicationBootstrap $app, $name, $basedir)
|
||||
{
|
||||
|
@ -133,6 +142,7 @@ class Module
|
|||
* Test for an enabled module by name
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function exists($name)
|
||||
|
@ -145,8 +155,10 @@ class Module
|
|||
*
|
||||
* @param string $name
|
||||
* @param bool $autoload
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Icinga\Exception\ProgrammingError When the module is not yet loaded
|
||||
*
|
||||
* @throws \Icinga\Exception\ProgrammingError When the module is not yet loaded
|
||||
*/
|
||||
public static function get($name, $autoload = false)
|
||||
{
|
||||
|
@ -238,7 +250,8 @@ class Module
|
|||
/**
|
||||
* Getter for module config object
|
||||
*
|
||||
* @param null|string $file
|
||||
* @param string $file
|
||||
*
|
||||
* @return Config
|
||||
*/
|
||||
public function getConfig($file = null)
|
||||
|
@ -373,9 +386,10 @@ class Module
|
|||
/**
|
||||
* Register hook
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $class
|
||||
* @param string $key
|
||||
* @param string $name
|
||||
* @param string $class
|
||||
* @param string $key
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected function registerHook($name, $key, $class)
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
use \Zend_Soap_Server as ZfSoapServer;
|
||||
use \Zend_Soap_AutoDiscover as ZfSoapAutoDiscover;
|
||||
use \Icinga\Web\Controller\ModuleActionController;
|
||||
use \Icinga\Web\Url;
|
||||
use \Monitoring\Backend;
|
||||
|
||||
use Icinga\Web\Controller\ModuleActionController;
|
||||
use Icinga\Web\Url;
|
||||
use Monitoring\Backend;
|
||||
use Zend_Soap_Server as ZfSoapServer;
|
||||
use Zend_Soap_AutoDiscover as ZfSoapAutoDiscover;
|
||||
|
||||
class Api
|
||||
{
|
||||
|
@ -22,7 +26,7 @@ try {
|
|||
} catch (Exception $e) {
|
||||
return array('error' => $e->getMessage());
|
||||
}
|
||||
return $result;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,3 +51,4 @@ class Monitoring_SoapController extends ModuleActionController
|
|||
exit;
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
|
Loading…
Reference in New Issue