1 | <?php |
||
8 | trait Config |
||
9 | { |
||
10 | /** |
||
11 | * |
||
12 | */ |
||
13 | use ArrayAccess; |
||
14 | use Iterator; |
||
15 | use PropertyAccess; |
||
16 | |||
17 | /** |
||
18 | * @var array|Configuration |
||
19 | */ |
||
20 | protected $config = []; |
||
21 | |||
22 | /** |
||
23 | * @param array $config |
||
24 | */ |
||
25 | 444 | function __construct($config = []) |
|
29 | |||
30 | /** |
||
31 | * @param string $name |
||
32 | * @return mixed |
||
33 | */ |
||
34 | 322 | function get($name) |
|
35 | { |
||
36 | 322 | return is_array($this->config) ? |
|
37 | 322 | (isset($this->config[$name]) ? $this->config[$name] : null) : $this->config[$name]; |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * @param string $name |
||
42 | * @return bool |
||
43 | */ |
||
44 | 39 | function has($name) |
|
45 | { |
||
46 | 39 | return isset($this->config[$name]); |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $name |
||
51 | * @return void |
||
52 | */ |
||
53 | 7 | function remove($name) |
|
57 | |||
58 | /** |
||
59 | * @param string $name |
||
60 | * @param mixed $value |
||
61 | * @return mixed |
||
62 | */ |
||
63 | 117 | function set($name, $value) |
|
67 | |||
68 | /** |
||
69 | * @param string $name |
||
70 | * @param mixed $value |
||
71 | * @return self|mixed |
||
72 | */ |
||
73 | 24 | function with($name, $value) |
|
83 | |||
84 | /** |
||
85 | * @param string $name |
||
86 | * @return self|mixed |
||
87 | */ |
||
88 | 3 | function without($name) |
|
98 | |||
99 | /** |
||
100 | * |
||
101 | */ |
||
102 | 48 | function __clone() |
|
127 | } |
||
128 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.