@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $this->{$option} = (string)$value; |
94 | 94 | break; |
95 | 95 | case 'adapter': |
96 | - foreach($value as $name => $adapter) { |
|
96 | + foreach ($value as $name => $adapter) { |
|
97 | 97 | $this->injectAdapter($name, $adapter); |
98 | 98 | } |
99 | 99 | break; |
@@ -127,13 +127,13 @@ discard block |
||
127 | 127 | /** |
128 | 128 | * {@inheritDoc} |
129 | 129 | */ |
130 | - public function injectAdapter($adapter, ?string $name=null) : AdapterAwareInterface |
|
130 | + public function injectAdapter($adapter, ?string $name = null) : AdapterAwareInterface |
|
131 | 131 | { |
132 | - if(!($adapter instanceof AdapterInterface)) { |
|
132 | + if (!($adapter instanceof AdapterInterface)) { |
|
133 | 133 | throw new Exception('adapter needs to implement AdapterInterface'); |
134 | 134 | } |
135 | 135 | |
136 | - if($name === null) { |
|
136 | + if ($name === null) { |
|
137 | 137 | $name = get_class($adapter); |
138 | 138 | } |
139 | 139 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @param array $config |
50 | 50 | */ |
51 | - public function __construct(Iterable $config=[]) |
|
51 | + public function __construct(Iterable $config = []) |
|
52 | 52 | { |
53 | 53 | $this->config = $config; |
54 | 54 | $container = $this; |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function get($name) |
68 | 68 | { |
69 | - if($this->has($name)) { |
|
69 | + if ($this->has($name)) { |
|
70 | 70 | return $this->service[$name]['instance']; |
71 | 71 | } else { |
72 | - if(isset($this->registry[$name])) { |
|
72 | + if (isset($this->registry[$name])) { |
|
73 | 73 | $this->service[$name]['instance'] = $this->registry[$name]->call($this); |
74 | 74 | unset($this->registry[$name]); |
75 | 75 | return $this->service[$name]['instance']; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function getNew(string $name) |
90 | 90 | { |
91 | - if(isset($this->registry[$name])) { |
|
91 | + if (isset($this->registry[$name])) { |
|
92 | 92 | return $this->registry[$name]->call($this); |
93 | 93 | } else { |
94 | 94 | return $this->autoWire($name); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function add(string $name, Closure $service): Container |
107 | 107 | { |
108 | - if($this->has($name)) { |
|
108 | + if ($this->has($name)) { |
|
109 | 109 | throw new Exception('service '.$name.' is already registered'); |
110 | 110 | } |
111 | 111 | |
@@ -133,18 +133,18 @@ discard block |
||
133 | 133 | * @param array $parents |
134 | 134 | * @return mixed |
135 | 135 | */ |
136 | - protected function autoWire(string $name, $config=null, array $parents=[]) |
|
136 | + protected function autoWire(string $name, $config = null, array $parents = []) |
|
137 | 137 | { |
138 | - if($config === null) { |
|
138 | + if ($config === null) { |
|
139 | 139 | $config = $this->config; |
140 | 140 | } |
141 | 141 | |
142 | 142 | $class = $name; |
143 | 143 | $sub_config = $config; |
144 | - if(isset($config[$name])) { |
|
145 | - if(isset($config[$name]['use'])) { |
|
144 | + if (isset($config[$name])) { |
|
145 | + if (isset($config[$name]['use'])) { |
|
146 | 146 | $class = $config[$name]['use']; |
147 | - } elseif(isset($config[$name]['name'])) { |
|
147 | + } elseif (isset($config[$name]['name'])) { |
|
148 | 148 | $class = $config[$name]['name']; |
149 | 149 | } |
150 | 150 | |
@@ -155,29 +155,29 @@ discard block |
||
155 | 155 | |
156 | 156 | try { |
157 | 157 | $reflection = new ReflectionClass($class); |
158 | - } catch(\Exception $e) { |
|
158 | + } catch (\Exception $e) { |
|
159 | 159 | throw new Exception($class.' can not be resolved to an existing class'); |
160 | 160 | } |
161 | 161 | |
162 | 162 | $constructor = $reflection->getConstructor(); |
163 | 163 | |
164 | - if($constructor === null) { |
|
164 | + if ($constructor === null) { |
|
165 | 165 | return new $class(); |
166 | 166 | } else { |
167 | 167 | $params = $constructor->getParameters(); |
168 | 168 | $args = []; |
169 | 169 | |
170 | - foreach($params as $param) { |
|
170 | + foreach ($params as $param) { |
|
171 | 171 | $type = $param->getClass(); |
172 | 172 | $param_name = $param->getName(); |
173 | 173 | |
174 | - if($type === null) { |
|
174 | + if ($type === null) { |
|
175 | 175 | try { |
176 | 176 | $args[$param_name] = $this->getParam($name, $param_name, $sub_config); |
177 | - } catch(Exception $e) { |
|
178 | - if($param->isDefaultValueAvailable()) { |
|
177 | + } catch (Exception $e) { |
|
178 | + if ($param->isDefaultValueAvailable()) { |
|
179 | 179 | $args[$param_name] = $param->getDefaultValue(); |
180 | - } elseif($param->allowsNull()) { |
|
180 | + } elseif ($param->allowsNull()) { |
|
181 | 181 | $args[$param_name] = null; |
182 | 182 | } else { |
183 | 183 | throw $e; |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | } else { |
187 | 187 | $type_class = $type->getName(); |
188 | 188 | |
189 | - if($type_class === $name) { |
|
189 | + if ($type_class === $name) { |
|
190 | 190 | throw new Exception('class '.$type_class.' can not depend on itself'); |
191 | 191 | } |
192 | 192 | |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | { |
211 | 211 | $service = null; |
212 | 212 | $services = $this->service; |
213 | - foreach(array_reverse($parents) as $name => $parent) { |
|
214 | - if(isset($services[$name])) { |
|
213 | + foreach (array_reverse($parents) as $name => $parent) { |
|
214 | + if (isset($services[$name])) { |
|
215 | 215 | $service = $services[$name]; |
216 | - if(isset($services['service'])) { |
|
216 | + if (isset($services['service'])) { |
|
217 | 217 | $services = $services['service']; } |
218 | 218 | else { |
219 | 219 | break; |
@@ -223,12 +223,12 @@ discard block |
||
223 | 223 | } |
224 | 224 | } |
225 | 225 | |
226 | - if($service !== null) { |
|
226 | + if ($service !== null) { |
|
227 | 227 | return $service['instance']; |
228 | 228 | } |
229 | 229 | |
230 | - foreach(array_reverse($parents) as $parent) { |
|
231 | - if(isset($parent['service'][$class])) { |
|
230 | + foreach (array_reverse($parents) as $parent) { |
|
231 | + if (isset($parent['service'][$class])) { |
|
232 | 232 | return $this->autoWire($class, $parent['service'], $parents); |
233 | 233 | } |
234 | 234 | } |
@@ -245,17 +245,17 @@ discard block |
||
245 | 245 | * @param array $args |
246 | 246 | * @return mixed |
247 | 247 | */ |
248 | - protected function createInstance(string $name, ReflectionClass $class, array $args, Iterable $config, $parents=[]) |
|
248 | + protected function createInstance(string $name, ReflectionClass $class, array $args, Iterable $config, $parents = []) |
|
249 | 249 | { |
250 | 250 | $instance = $class->newInstanceArgs($args); |
251 | 251 | |
252 | 252 | $loop = &$this->service; |
253 | - foreach($parents as $p => $parent) { |
|
253 | + foreach ($parents as $p => $parent) { |
|
254 | 254 | $loop = &$loop[$p]; |
255 | 255 | } |
256 | - if(count($parents) === 0) { |
|
256 | + if (count($parents) === 0) { |
|
257 | 257 | $loop[$name]['instance'] = $instance; |
258 | - } else { |
|
258 | + } else { |
|
259 | 259 | $loop['service'][$name]['instance'] = $instance; |
260 | 260 | } |
261 | 261 | |
@@ -265,15 +265,15 @@ discard block |
||
265 | 265 | |
266 | 266 | array_unshift($parents, $name); |
267 | 267 | |
268 | - if($instance instanceof AdapterAwareInterface) { |
|
269 | - if(isset($config['adapter'])) { |
|
268 | + if ($instance instanceof AdapterAwareInterface) { |
|
269 | + if (isset($config['adapter'])) { |
|
270 | 270 | $adapters = $config['adapter']; |
271 | 271 | } else { |
272 | 272 | $adapters = $instance->getDefaultAdapter(); |
273 | 273 | } |
274 | 274 | |
275 | - foreach($adapters as $adapter => $service) { |
|
276 | - if(isset($service['enabled']) && $service['enabled'] === '0') { |
|
275 | + foreach ($adapters as $adapter => $service) { |
|
276 | + if (isset($service['enabled']) && $service['enabled'] === '0') { |
|
277 | 277 | continue; |
278 | 278 | } |
279 | 279 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | $class = $adapter; |
283 | 283 | $adapter_instance = $this->autoWire($class, $adapters, $parents); |
284 | 284 | |
285 | - if(isset($service['expose']) && $service['expose']) { |
|
285 | + if (isset($service['expose']) && $service['expose']) { |
|
286 | 286 | $this->service[$adapter]['instance'] = $adapter_instance; |
287 | 287 | } |
288 | 288 | |
@@ -302,22 +302,22 @@ discard block |
||
302 | 302 | */ |
303 | 303 | protected function parseParam($param) |
304 | 304 | { |
305 | - if(is_iterable($param)) { |
|
306 | - foreach($param as $key => $value) { |
|
305 | + if (is_iterable($param)) { |
|
306 | + foreach ($param as $key => $value) { |
|
307 | 307 | $param[$key] = $this->parseParam($value); |
308 | 308 | } |
309 | 309 | |
310 | 310 | return $param; |
311 | - } elseif(is_string($param)) { |
|
312 | - if(preg_match('#\{ENV\(([A-Za-z0-9_]+)(?:(,?)(.*))\)\}#', $param, $match)) { |
|
313 | - if(count($match) !== 4) { |
|
311 | + } elseif (is_string($param)) { |
|
312 | + if (preg_match('#\{ENV\(([A-Za-z0-9_]+)(?:(,?)(.*))\)\}#', $param, $match)) { |
|
313 | + if (count($match) !== 4) { |
|
314 | 314 | return $param; |
315 | 315 | } |
316 | 316 | |
317 | 317 | $env = getenv($match[1]); |
318 | - if($env === false && !empty($match[3])) { |
|
318 | + if ($env === false && !empty($match[3])) { |
|
319 | 319 | return str_replace($match[0], $match[3], $param); |
320 | - } elseif($env === false) { |
|
320 | + } elseif ($env === false) { |
|
321 | 321 | throw new Exception('env variable '.$match[1].' required but it is neither set not a default value exists'); |
322 | 322 | } else { |
323 | 323 | return str_replace($match[0], $env, $param); |
@@ -340,13 +340,13 @@ discard block |
||
340 | 340 | * @param string $param |
341 | 341 | * @return mixed |
342 | 342 | */ |
343 | - public function getParam(string $name, string $param, ?Iterable $config=null) |
|
343 | + public function getParam(string $name, string $param, ?Iterable $config = null) |
|
344 | 344 | { |
345 | - if($config === null) { |
|
345 | + if ($config === null) { |
|
346 | 346 | $config = $this->config; |
347 | 347 | } |
348 | 348 | |
349 | - if(!isset($config[$name]['options'][$param])) { |
|
349 | + if (!isset($config[$name]['options'][$param])) { |
|
350 | 350 | throw new Exception('no configuration available for required service parameter '.$param); |
351 | 351 | } |
352 | 352 |
@@ -71,16 +71,16 @@ discard block |
||
71 | 71 | * @param Iterable $config |
72 | 72 | * @return Log |
73 | 73 | */ |
74 | - public function setOptions(? Iterable $config = null): Log |
|
74 | + public function setOptions(? Iterable $config = null) : Log |
|
75 | 75 | { |
76 | 76 | if ($config === null) { |
77 | 77 | return $this; |
78 | 78 | } |
79 | 79 | |
80 | 80 | foreach ($config as $option => $value) { |
81 | - switch($option) { |
|
81 | + switch ($option) { |
|
82 | 82 | case 'adapter': |
83 | - foreach($value as $name => $adapter) { |
|
83 | + foreach ($value as $name => $adapter) { |
|
84 | 84 | $this->injectAdapter($name, $adapter); |
85 | 85 | } |
86 | 86 | break; |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | /** |
115 | 115 | * {@inheritDoc} |
116 | 116 | */ |
117 | - public function injectAdapter($adapter, ?string $name=null) : AdapterAwareInterface |
|
117 | + public function injectAdapter($adapter, ?string $name = null) : AdapterAwareInterface |
|
118 | 118 | { |
119 | - if(!($adapter instanceof AdapterInterface)) { |
|
119 | + if (!($adapter instanceof AdapterInterface)) { |
|
120 | 120 | throw new Exception('adapter needs to implement AdapterInterface'); |
121 | 121 | } |
122 | 122 | |
123 | - if($name === null) { |
|
123 | + if ($name === null) { |
|
124 | 124 | $name = get_class($adapter); |
125 | 125 | } |
126 | 126 |
@@ -37,7 +37,7 @@ |
||
37 | 37 | * @param string $name |
38 | 38 | * @return AdapterAwareInterface |
39 | 39 | */ |
40 | - public function injectAdapter($adapter, ?string $name=null): AdapterAwareInterface; |
|
40 | + public function injectAdapter($adapter, ?string $name = null) : AdapterAwareInterface; |
|
41 | 41 | |
42 | 42 | |
43 | 43 | /** |