From ea4b6c7699a7fbb7be3d9e5ce86c84a36b63f569 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 15 Mar 2015 19:13:25 +0100 Subject: Move get/set-Calls into ModelBase and abstract all access into a Model Conflicts: model/Overview.php model/Room.php model/StreamList.php tests/ModelTestbase.php --- model/ModelBase.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 model/ModelBase.php (limited to 'model/ModelBase.php') diff --git a/model/ModelBase.php b/model/ModelBase.php new file mode 100644 index 0000000..1ee41b4 --- /dev/null +++ b/model/ModelBase.php @@ -0,0 +1,42 @@ +_has($GLOBALS['CONFIG'], $keychain); + } + private 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 $this->_has($array[$key], array_slice($keychain, 1)); + } + + protected function get($keychain, $default = null) + { + return $this->_get($GLOBALS['CONFIG'], $keychain, $default); + } + private 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 $this->_get($array[$key], array_slice($keychain, 1), $default); + } +} -- cgit v1.2.3