aboutsummaryrefslogtreecommitdiff
path: root/model/ModelBase.php
blob: 1ee41b46b83730e441cd8145aa2e3cdcce665b7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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);
	}
}