Config: Remove base path subsitution
Test for leading slash and prepend base path to allow absolute configuration files. fixes #5556
This commit is contained in:
parent
5559cf6c2b
commit
79fb8b1e0d
|
@ -82,7 +82,7 @@ class Config extends Zend_Config
|
|||
$filepath = realpath($filename);
|
||||
if ($filepath === false) {
|
||||
$this->configFile = $filename;
|
||||
} else if (is_readable($filepath)) {
|
||||
} elseif (is_readable($filepath)) {
|
||||
$this->configFile = $filepath;
|
||||
$this->merge(new Zend_Config_Ini($filepath));
|
||||
} else {
|
||||
|
@ -102,8 +102,7 @@ class Config extends Zend_Config
|
|||
public static function app($configname = 'config', $fromDisk = false)
|
||||
{
|
||||
if (!isset(self::$app[$configname]) || $fromDisk) {
|
||||
$filename = self::$configDir . '/' . $configname . '.ini';
|
||||
self::$app[$configname] = new Config($filename);
|
||||
self::$app[$configname] = new Config(self::resolvePath($configname . '.ini'));
|
||||
}
|
||||
return self::$app[$configname];
|
||||
}
|
||||
|
@ -125,7 +124,7 @@ class Config extends Zend_Config
|
|||
$moduleConfigs = self::$modules[$modulename];
|
||||
if (!isset($moduleConfigs[$configname]) || $fromDisk) {
|
||||
$moduleConfigs[$configname] = new Config(
|
||||
self::$configDir . '/modules/' . $modulename . '/' . $configname . '.ini'
|
||||
self::resolvePath('modules/' . $modulename . '/' . $configname . '.ini')
|
||||
);
|
||||
}
|
||||
return $moduleConfigs[$configname];
|
||||
|
@ -159,21 +158,17 @@ class Config extends Zend_Config
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the input path with resolved path variables
|
||||
* Prepend configuration base dir if input is relative
|
||||
*
|
||||
* Currently only %app% is considered a path variable and points to the application paths
|
||||
*
|
||||
* @param string $path The path to resolve
|
||||
*
|
||||
* @return string The resolved path
|
||||
* @param string $path Input path
|
||||
* @return string Absolute path
|
||||
*/
|
||||
public static function resolvePath($path)
|
||||
{
|
||||
try {
|
||||
$appDir = realpath(Icinga::app()->getApplicationDir() . '/..');
|
||||
} catch (ProgrammingError $appNotStarted) {
|
||||
$appDir = realpath(__DIR__ . '/../../..');
|
||||
if (strpos($path, DIRECTORY_SEPARATOR) === 0) {
|
||||
return $path;
|
||||
}
|
||||
return str_replace('{app}', $appDir, $path);
|
||||
|
||||
return self::$configDir . DIRECTORY_SEPARATOR . $path;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ class FileWriter extends LogWriter
|
|||
*/
|
||||
public function __construct(Zend_Config $config)
|
||||
{
|
||||
$this->path = Config::resolvePath($config->target);
|
||||
$this->path = $config->target;
|
||||
$this->setup();
|
||||
}
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ abstract class PreferencesStore
|
|||
}
|
||||
|
||||
if ($type === 'Ini') {
|
||||
$config->location = IcingaConfig::resolvePath($config->config_path);
|
||||
$config->location = $config->config_path;
|
||||
} elseif ($type === 'Db') {
|
||||
$config->connection = new DbConnection(ResourceFactory::getResourceConfig($config->resource));
|
||||
}
|
||||
|
|
|
@ -81,7 +81,6 @@ class WritablePathValidator extends Zend_Validate_Abstract
|
|||
$value = (string) $value;
|
||||
|
||||
$this->_setValue($value);
|
||||
$value = IcingaConfig::resolvePath($value);
|
||||
if ($this->requireExistence && !file_exists($value)) {
|
||||
$this->_error('DOES_NOT_EXIST');
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue