blob: 02080de40e015b9a3781b9af3aa512b3cf2187d3 (
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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
<?php
namespace Engelsystem\Config;
use ErrorException;
class Config
{
/**
* @var self
*/
protected static $instance;
/**
* The config values
*
* @var array
*/
protected $data = [];
/**
* @param string|null $key
* @param mixed $default
* @return mixed
*/
public function get($key, $default = null)
{
if (is_null($key)) {
return $this->data;
}
if ($this->has($key)) {
return $this->data[$key];
}
return $default;
}
/**
* @param string|array $key
* @param mixed $value
*/
public function set($key, $value = null)
{
if (is_array($key)) {
foreach ($key as $configKey => $configValue) {
$this->set($configKey, $configValue);
}
return;
}
$this->data[$key] = $value;
}
/**
* @param string $key
* @return bool
*/
public function has($key)
{
return isset($this->data[$key]);
}
/**
* @param string $key
*/
public function remove($key)
{
unset($this->data[$key]);
}
/**
* @param string $key
* @return mixed
*/
public function __get($key)
{
return $this->get($key);
}
/**
* @param string $key
* @param mixed $value
*/
public function __set($key, $value)
{
$this->set($key, $value);
}
/**
* @param string $key
* @return bool
*/
public function __isset($key)
{
return $this->has($key);
}
/**
* @param string $key
*/
public function __unset($key)
{
$this->remove($key);
}
/**
* @return Config
* @throws ErrorException
*/
public static function getInstance()
{
if (!self::$instance instanceof self) {
throw new ErrorException('Config not initialized');
}
return self::$instance;
}
/**
* @param self $instance
*/
public static function setInstance($instance)
{
self::$instance = $instance;
}
}
|