diff --git a/src/includes/class/class.LSconfig.php b/src/includes/class/class.LSconfig.php index 54f6bcb0..b442db5e 100644 --- a/src/includes/class/class.LSconfig.php +++ b/src/includes/class/class.LSconfig.php @@ -59,6 +59,57 @@ class LSconfig { return false; } + /** + * Explode configuration variable keys + * @param string $value The variable name to explode + * @return array The exploded variable keys + */ + public static function explode_keys($value) { + $keys = []; + $key = ""; + for($i=0; $i|string> $args Function arguments could be an array of key or a key + * to implode + * @return string The imploded configuration variable keys + */ + public static function implode_keys(...$args) { + $keys = []; + foreach ($args as $arg) + if (is_array($arg)) + $keys = array_merge($keys, $arg); + else + $keys[] = $arg; + return implode('.', array_map(['LSconfig', 'escape_key'], $keys)); + } + /** * Get a specific configuration variable value * @@ -73,7 +124,7 @@ class LSconfig { * @return mixed The configuration variable value **/ public static function get($var, $default=null, $cast=null, $data=null) { - $vars = explode('.', $var); + $vars = self :: explode_keys($var); $value = $default; if (is_array($vars)) { $value = (is_array($data)?$data:self :: $data); @@ -142,7 +193,7 @@ class LSconfig { } else { foreach ($subkeys as $subkey) { - $key = "$root_key.$subkey"; + $key = self :: implode_keys(self :: explode_keys($root_key), $subkey); $return[$key] = self :: get($key, $default, $cast, $data); } } @@ -163,7 +214,7 @@ class LSconfig { * @return boolean True si tout s'est bien passé, False sinon **/ public static function set($var,$val) { - $vars=explode('.',$var); + $vars = self :: explode_keys($var); if(is_array($vars)) { $code='self :: $data'; foreach ($vars as $v) {