aboutsummaryrefslogtreecommitdiff
path: root/model/ModelBase.php
blob: 7b1370b55cf3f520220ca4f6c075702ee8037b69 (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
43
44
45
46
47
48
49
50
<?php

class ModelBase
{
	protected function has($keychain)
	{
		return ModelBase::_has($GLOBALS['CONFIG'], $keychain);
	}
	protected static function staticHas($keychain)
	{
		return ModelBase::_has($GLOBALS['CONFIG'], $keychain);
	}
	private static 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 ModelBase::_has($array[$key], array_slice($keychain, 1));
	}

	protected function get($keychain, $default = null)
	{
		return ModelBase::_get($GLOBALS['CONFIG'], $keychain, $default);
	}
	protected static function staticGet($keychain, $default = null)
	{
		return ModelBase::_get($GLOBALS['CONFIG'], $keychain, $default);
	}
	private static 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 ModelBase::_get($array[$key], array_slice($keychain, 1), $default);
	}
}