aboutsummaryrefslogtreecommitdiff
path: root/model/ModelBase.php
blob: 41f329b03c88492158d133a3d6a1047806611195 (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 $config;
	public function __construct($config)
	{
		$this->config = $config;
	}

	public function has($keychain)
	{
		return ModelBase::_has($this->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));
	}

	public function get($keychain, $default = null)
	{
		return ModelBase::_get($this->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);
	}
}