-
Notifications
You must be signed in to change notification settings - Fork 7
/
FinderConfig.php
106 lines (86 loc) · 2.11 KB
/
FinderConfig.php
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* Description of FinderConfig
*
* Parses ini files to a FinderConfig Object
*
* The main instance of FinderConfig is a Singleton (and could only exist once)
* The instance could have multiple instances of FinderConfig within it self, so
* that multi dimentional array's can be parsed as a multy layered object
*
* @author niele
*
* @todo extract the path to the ini file and make it variable
*
*/
class FinderConfig
{
/**
* Path to default config file
*/
const DEFAULT_CONFIG_FILE = 'config.ini';
/**
* PlaceHolder for self (Singleton)
*
* @var FinderConfig
*/
public static $instance;
/**
* Get the Instance of self
*
* @return FinderConfig
*/
public static function getInstance()
{
if (null == self::$instance) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Constructor Class
*
* @param array $config
* @access private
*/
private function __construct(array $options=array())
{
if (empty($options)) {
$options = parse_ini_file(
APPLICATION_PATH . self::DEFAULT_CONFIG_FILE,
true
);
}
$this->setConfig($options);
}
/**
* Set config options, sets recurivly if it's a multydimentional array
*
* @param array $options
* @access private
* @return FinderConfig
*/
private function setConfig(array $options=array())
{
foreach ($options as $key => $value) {
if (is_array($value) && !empty($value)) {
$value = new self($value);
}
$this->$key = $value;
}
return $this;
}
/**
* Magic method get
*
* This gets triggered if there is a call made to an undefined property in
* the FinderConfig instance or subInstance, so we throw an Exception
*
* @param string $name
* @throws Exception
*/
public function __get($name)
{
throw new Exception('call to undefined property: ' . $name);
}
}