diff options
Diffstat (limited to 'lib/helper.php')
-rw-r--r-- | lib/helper.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/helper.php b/lib/helper.php index 2127c14..98397e4 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -96,3 +96,41 @@ function strtoduration($str) $parts = explode(':', $str); return ((int)$parts[0] * 60 + (int)$parts[1]) * 60; } + +function has($keychain) +{ + return _has($GLOBALS['CONFIG'], $keychain); +} +function _has($array, $keychain) +{ + if(!is_array($keychain)) + $keychain = explode('.', $keychain); + + $key = $keychain[0]; + if(!isset($array[$key])) + return false; + + if(count($keychain) == 1) + return true; + + return _has($array[$key], array_slice($keychain, 1)); +} + +function get($keychain, $default = null) +{ + return _get($GLOBALS['CONFIG'], $keychain, $default); +} +function _get($array, $keychain, $default) +{ + if(!is_array($keychain)) + $keychain = explode('.', $keychain); + + $key = $keychain[0]; + if(!isset($array[$key])) + return $default; + + if(count($keychain) == 1) + return $array[$key]; + + return _get($array[$key], array_slice($keychain, 1), $default); +} |