aboutsummaryrefslogtreecommitdiff
path: root/model/ModelBase.php
diff options
context:
space:
mode:
authorMaZderMind2015-03-15 19:13:25 +0100
committerMaZderMind2015-03-29 21:42:01 +0200
commitea4b6c7699a7fbb7be3d9e5ce86c84a36b63f569 (patch)
treec919029a8b12e43c363b898a1ff9f7adf5c3312b /model/ModelBase.php
parent97fe6bf0af2989abbaaba138df3c54c4e55af3c9 (diff)
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
Diffstat (limited to 'model/ModelBase.php')
-rw-r--r--model/ModelBase.php42
1 files changed, 42 insertions, 0 deletions
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 @@
+<?php
+
+class Modelbase
+{
+ protected function has($keychain)
+ {
+ return $this->_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);
+ }
+}