From bfa834fc3b2ea28c13929b4d3a6fcb545fb0292d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 13 Nov 2014 09:33:31 +0100 Subject: [PATCH] Remove constant ICINGAWEB_APPDIR We should avoid use of constants. --- application/clicommands/WebCommand.php | 3 +- .../Config/General/ApplicationConfigForm.php | 10 +++--- .../Application/ApplicationBootstrap.php | 31 +++++++++---------- .../Icinga/Application/Modules/Manager.php | 10 ++++++ library/Icinga/Cli/Loader.php | 2 +- 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/application/clicommands/WebCommand.php b/application/clicommands/WebCommand.php index 11e7f002a..5d9b20c64 100644 --- a/application/clicommands/WebCommand.php +++ b/application/clicommands/WebCommand.php @@ -4,6 +4,7 @@ namespace Icinga\Clicommands; +use Icinga\Application\Icinga; use Icinga\Cli\Command; use Icinga\Exception\IcingaException; @@ -30,7 +31,7 @@ class WebCommand extends Command // throw new IcingaException('Socket is required'); } if ($basedir === null) { - $basedir = dirname(ICINGAWEB_APPDIR) . '/public'; + $basedir = Icinga::app()->getBaseDir('public'); if (! file_exists($basedir) || ! is_dir($basedir)) { throw new IcingaException('Basedir is required'); } diff --git a/application/forms/Config/General/ApplicationConfigForm.php b/application/forms/Config/General/ApplicationConfigForm.php index fda695886..6a35074d2 100644 --- a/application/forms/Config/General/ApplicationConfigForm.php +++ b/application/forms/Config/General/ApplicationConfigForm.php @@ -5,9 +5,11 @@ namespace Icinga\Form\Config\General; use DateTimeZone; -use Icinga\Web\Form; -use Icinga\Util\Translator; +use Icinga\Application\Icinga; use Icinga\Data\ResourceFactory; +use Icinga\Util\Translator; +use Icinga\Web\Form; + /** * Form class to modify the general application configuration @@ -71,12 +73,12 @@ class ApplicationConfigForm extends Form array( 'label' => t('Module Path'), 'required' => true, + 'value' => implode(':', Icinga::app()->getModuleManager()->getModuleDirs()), 'description' => t( 'Contains the directories that will be searched for available modules, separated by ' . 'colons. Modules that don\'t exist in these directories can still be symlinked in ' . 'the module folder, but won\'t show up in the list of disabled modules.' - ), - 'value' => realpath(ICINGAWEB_APPDIR . '/../modules') + ) ) ); diff --git a/library/Icinga/Application/ApplicationBootstrap.php b/library/Icinga/Application/ApplicationBootstrap.php index 4d0f17f31..9940f1901 100644 --- a/library/Icinga/Application/ApplicationBootstrap.php +++ b/library/Icinga/Application/ApplicationBootstrap.php @@ -49,6 +49,13 @@ abstract class ApplicationBootstrap */ protected $baseDir; + /** + * Application directory + * + * @var string + */ + protected $appDir; + /** * Icinga auto loader * @@ -77,13 +84,6 @@ abstract class ApplicationBootstrap */ private $configDir; - /** - * Application directory - * - * @var string - */ - private $appDir; - /** * Module manager * @@ -117,11 +117,10 @@ abstract class ApplicationBootstrap $baseDir = dirname($this->getBootstrapDirectory()); } $this->baseDir = $baseDir; + $this->appDir = $baseDir . '/application'; define('ICINGAWEB_VENDORS', $baseDir . '/library/vendor'); - define('ICINGAWEB_APPDIR', $baseDir . '/application'); - $this->appDir = ICINGAWEB_APPDIR; $this->libDir = realpath(__DIR__ . '/../..'); if ($configDir === null) { @@ -227,21 +226,19 @@ abstract class ApplicationBootstrap */ public function getBaseDir($subDir = null) { - return $this->getDirWithSubDir($subDir); + return $this->getDirWithSubDir($this->baseDir, $subDir); } /** - * Getter for application dir + * Get the application directory * - * Optional append sub directory - * - * @param string $subdir optional subdir + * @param string $subDir Optional sub directory to get * * @return string */ - public function getApplicationDir($subdir = null) + public function getApplicationDir($subDir = null) { - return $this->getDirWithSubDir($this->appDir, $subdir); + return $this->getDirWithSubDir($this->appDir, $subDir); } /** @@ -331,7 +328,7 @@ abstract class ApplicationBootstrap $this->moduleManager = new ModuleManager( $this, $this->configDir . '/enabledModules', - explode(':', $this->config->fromSection('global', 'modulePath', ICINGAWEB_APPDIR . '/../modules')) + explode(':', $this->config->fromSection('global', 'modulePath', $this->baseDir . '/modules')) ); return $this; } diff --git a/library/Icinga/Application/Modules/Manager.php b/library/Icinga/Application/Modules/Manager.php index 984e528d2..8857bf2d2 100644 --- a/library/Icinga/Application/Modules/Manager.php +++ b/library/Icinga/Application/Modules/Manager.php @@ -559,4 +559,14 @@ class Manager ksort($this->installedBaseDirs); return $this; } + + /** + * Get the directories where to look for installed modules + * + * @return array + */ + public function getModuleDirs() + { + return $this->modulePaths; + } } diff --git a/library/Icinga/Cli/Loader.php b/library/Icinga/Cli/Loader.php index 11ca2b70b..f0aa95499 100644 --- a/library/Icinga/Cli/Loader.php +++ b/library/Icinga/Cli/Loader.php @@ -66,7 +66,7 @@ class Loader public function __construct(App $app) { $this->app = $app; - $this->coreAppDir = ICINGAWEB_APPDIR . '/clicommands'; + $this->coreAppDir = $app->getBaseDir('clicommands'); } /**