Implement ApplicationBootstrap::getStorageDir()

refs #2582
This commit is contained in:
Alexander A. Klimov 2017-11-08 16:07:12 +01:00 committed by Eric Lippmann
parent 3d50729847
commit cea52a1b4b
1 changed files with 34 additions and 3 deletions

View File

@ -77,6 +77,13 @@ abstract class ApplicationBootstrap
*/
protected $configDir;
/**
* Common storage directory
*
* @var string
*/
protected $storageDir;
/**
* Icinga class loader
*
@ -122,10 +129,11 @@ abstract class ApplicationBootstrap
/**
* Constructor
*
* @param string $baseDir Icinga Web 2 base directory
* @param string $configDir Path to Icinga Web 2's configuration files
* @param string $baseDir Icinga Web 2 base directory
* @param string $configDir Path to Icinga Web 2's configuration files
* @param string $storageDir Path to Icinga Web 2's stored files
*/
protected function __construct($baseDir = null, $configDir = null)
protected function __construct($baseDir = null, $configDir = null, $storageDir = null)
{
if ($baseDir === null) {
$baseDir = dirname($this->getBootstrapDirectory());
@ -148,6 +156,17 @@ abstract class ApplicationBootstrap
$canonical = realpath($configDir);
$this->configDir = $canonical ? $canonical : $configDir;
if ($storageDir === null) {
$storageDir = getenv('ICINGAWEB_STORAGEDIR');
if ($storageDir === false) {
$storageDir = Platform::isWindows()
? $baseDir . '/storage'
: '/var/lib/icingaweb2';
}
}
$canonical = realpath($storageDir);
$this->storageDir = $canonical ? $canonical : $storageDir;
set_include_path(
implode(
PATH_SEPARATOR,
@ -284,6 +303,18 @@ abstract class ApplicationBootstrap
return $this->getDirWithSubDir($this->configDir, $subDir);
}
/**
* Get the common storage directory
*
* @param string $subDir Optional sub directory to get
*
* @return string
*/
public function getStorageDir($subDir = null)
{
return $this->getDirWithSubDir($this->storageDir, $subDir);
}
/**
* Get the Icinga library directory
*