aboutsummaryrefslogtreecommitdiff
path: root/model/ModelBase.php
diff options
context:
space:
mode:
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);
+ }
+}