1 | <?php |
||
14 | class Config implements ConfigInterface |
||
15 | { |
||
16 | /** |
||
17 | * Array of parameters (with some default values) |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | private $_parameters = [ |
||
22 | 'legacy' => Client::LEGACY, |
||
23 | 'ssl' => Client::SSL, |
||
24 | 'timeout' => Client::TIMEOUT, |
||
25 | 'attempts' => Client::ATTEMPTS, |
||
26 | 'delay' => Client::ATTEMPTS_DELAY |
||
27 | ]; |
||
28 | |||
29 | /** |
||
30 | * Config constructor. |
||
31 | * |
||
32 | * @param array $parameters List of parameters which can be set on object creation stage |
||
33 | * @throws ConfigException |
||
34 | * @since 0.6 |
||
35 | */ |
||
36 | 14 | public function __construct(array $parameters = []) |
|
42 | |||
43 | /** |
||
44 | * Check if key in list of parameters |
||
45 | * |
||
46 | * @param string $key |
||
47 | * @param array $array |
||
48 | * @throws ConfigException |
||
49 | */ |
||
50 | 12 | private function exceptionIfKeyNotExist(string $key, array $array) |
|
56 | |||
57 | /** |
||
58 | * Compare data types of some value |
||
59 | * |
||
60 | * @param string $name Name of value |
||
61 | * @param mixed $whatType What type has value |
||
62 | * @param mixed $isType What type should be |
||
63 | * @throws ConfigException |
||
64 | */ |
||
65 | 8 | private function exceptionIfTypeMismatch(string $name, $whatType, $isType) |
|
71 | |||
72 | /** |
||
73 | * Set parameter into array |
||
74 | * |
||
75 | * @param string $name |
||
76 | * @param mixed $value |
||
77 | * @return \RouterOS\Config |
||
78 | * @throws ConfigException |
||
79 | */ |
||
80 | 9 | public function set(string $name, $value): Config |
|
93 | |||
94 | /** |
||
95 | * Return port number (get from defaults if port is not set by user) |
||
96 | * |
||
97 | * @param string $parameter |
||
98 | * @return bool|int |
||
99 | */ |
||
100 | 6 | private function getPort(string $parameter) |
|
111 | |||
112 | /** |
||
113 | * Remove parameter from array by name |
||
114 | * |
||
115 | * @param string $parameter |
||
116 | * @return \RouterOS\Config |
||
117 | * @throws ConfigException |
||
118 | */ |
||
119 | 3 | public function delete(string $parameter): Config |
|
129 | |||
130 | /** |
||
131 | * Return parameter of current config by name |
||
132 | * |
||
133 | * @param string $parameter |
||
134 | * @return mixed |
||
135 | * @throws ConfigException |
||
136 | */ |
||
137 | 7 | public function get(string $parameter) |
|
144 | |||
145 | /** |
||
146 | * Return array with all parameters of configuration |
||
147 | * |
||
148 | * @return array |
||
149 | */ |
||
150 | 8 | public function getParameters(): array |
|
154 | } |
||
155 |