openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit e9f583b9f1ee88bb48fca22dc79af536969274d5
parent 645f12e621c457ea2ebbbb4ff53bfd0bfb946153
Author: Jan Dankert <devnull@localhost>
Date:   Tue, 29 May 2018 22:58:35 +0200

Aufgehübscht...

Diffstat:
modules/configuration/Configuration.class.php | 35++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/modules/configuration/Configuration.class.php b/modules/configuration/Configuration.class.php @@ -59,7 +59,7 @@ class Configuration // Resolve variables in all custom configuration values array_walk_recursive( $customConfig, function(&$value,$key) { - $value = Configuration::evaluateFilename($value); + $value = Configuration::resolveVariables($value); } ); @@ -73,13 +73,12 @@ class Configuration // Load include files. foreach ($customConfig['include'] as $key => $file) { - if (substr($file, -4) == '.yml' || substr($file, -8) == '.yml.php') { - + if (substr($file, -4) == '.yml' || + substr($file, -5) == '.yaml' || + substr($file, -8) == '.yml.php' ) $customConfig += Configuration::loadCustomConfig($file); - - } else { - error_log('Warning: ' . $file . ' is no YAML and no INI - not loaded'); - } + else + error_log('Warning: ' . $file . ' is no .yml file - not loaded'); } } @@ -113,21 +112,27 @@ class Configuration } /** - * Evaluates variables in an include file string. - * Example: config-{http:host}.yml => config-yourdomain.yml - * @param $file String filename + * Evaluates variables in a text value. + * Examples: + * - config-${http:host}.yml => config-yourdomain.yml + * - config-${server:http-host}.yml => config-yourdomain.yml + * - config-${env:myvar}.yml => config-myvalue.yml + * @param $value String Configuration value * @return String */ - private static function evaluateFilename($file) + private static function resolveVariables($value) { return preg_replace_callback( "|\\$\{([[:alnum:]]+)\:([[:alnum:]_]+)\}|", - function ($match) { - $type = $match[1]; + function ($match) + { + $type = $match[1]; $value = $match[2]; $value = str_replace('-', '_', $value); - switch (strtolower($type)) { + + switch( strtolower( $type ) ) + { case 'env': return getenv(strtoupper($value)); @@ -141,7 +146,7 @@ class Configuration } }, - $file); + $value); } }