Remove constant ICINGAWEB_APPDIR

We should avoid use of constants.
This commit is contained in:
Eric Lippmann 2014-11-13 09:33:31 +01:00
parent 9c103a9864
commit bfa834fc3b
5 changed files with 33 additions and 23 deletions

View File

@ -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');
}

View File

@ -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')
)
)
);

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -66,7 +66,7 @@ class Loader
public function __construct(App $app)
{
$this->app = $app;
$this->coreAppDir = ICINGAWEB_APPDIR . '/clicommands';
$this->coreAppDir = $app->getBaseDir('clicommands');
}
/**