@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @param array $config |
49 | 49 | */ |
50 | - public function __construct(array $config=[]) |
|
50 | + public function __construct(array $config = []) |
|
51 | 51 | { |
52 | 52 | $this->config = $config; |
53 | 53 | } |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function get(string $name) |
63 | 63 | { |
64 | - if($this->has($name)) { |
|
64 | + if ($this->has($name)) { |
|
65 | 65 | return $this->service[$name]; |
66 | 66 | } else { |
67 | - if(isset($this->registry[$name])) { |
|
67 | + if (isset($this->registry[$name])) { |
|
68 | 68 | $this->service[$name] = $this->registry[$name]->call($this); |
69 | 69 | unset($this->registry[$name]); |
70 | 70 | return $this->service[$name]; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function add(string $name, Closure $service): Container |
86 | 86 | { |
87 | - if($this->has($name)) { |
|
87 | + if ($this->has($name)) { |
|
88 | 88 | throw new Exception('service '.$name.' is already registered'); |
89 | 89 | } |
90 | 90 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | */ |
113 | 113 | protected function autoWire(string $name) |
114 | 114 | { |
115 | - if(isset($this->config[$name]) && isset($this->config[$name]['class'])) { |
|
115 | + if (isset($this->config[$name]) && isset($this->config[$name]['class'])) { |
|
116 | 116 | $class = $this->config[$name]['class']; |
117 | 117 | } else { |
118 | 118 | $class = $name; |
@@ -121,21 +121,21 @@ discard block |
||
121 | 121 | $reflection = new ReflectionClass($class); |
122 | 122 | $constructor = $reflection->getConstructor(); |
123 | 123 | |
124 | - if($constructor === null) { |
|
124 | + if ($constructor === null) { |
|
125 | 125 | return new $class(); |
126 | 126 | } else { |
127 | 127 | $params = $constructor->getParameters(); |
128 | 128 | $args = []; |
129 | 129 | |
130 | - foreach($params as $param) { |
|
130 | + foreach ($params as $param) { |
|
131 | 131 | $type = $param->getClass(); |
132 | 132 | $param_name = $param->getName(); |
133 | 133 | |
134 | - if($type === null) { |
|
134 | + if ($type === null) { |
|
135 | 135 | try { |
136 | 136 | $args[$param_name] = $this->getParam($name, $param_name); |
137 | - } catch(Exception $e) { |
|
138 | - if($param->isDefaultValueAvailable()) { |
|
137 | + } catch (Exception $e) { |
|
138 | + if ($param->isDefaultValueAvailable()) { |
|
139 | 139 | $args[$param_name] = $param->getDefaultValue(); |
140 | 140 | } else { |
141 | 141 | throw $e; |
@@ -163,14 +163,14 @@ discard block |
||
163 | 163 | protected function createInstance(string $name, ReflectionClass $class, array $args) |
164 | 164 | { |
165 | 165 | $instance = $class->newInstanceArgs($args); |
166 | - if($instance instanceof AdapterAwareInterface) { |
|
167 | - if(isset($this->config[$name]) && isset($this->config[$name]['adapter'])) { |
|
168 | - foreach($this->config[$name]['adapter'] as $adapter => $config) { |
|
169 | - if(!isset($config['class'])) { |
|
166 | + if ($instance instanceof AdapterAwareInterface) { |
|
167 | + if (isset($this->config[$name]) && isset($this->config[$name]['adapter'])) { |
|
168 | + foreach ($this->config[$name]['adapter'] as $adapter => $config) { |
|
169 | + if (!isset($config['class'])) { |
|
170 | 170 | throw new Exception('adapter requires class configuration'); |
171 | 171 | } |
172 | 172 | |
173 | - if(isset($config['enabled']) && $config['enabled'] === '0') { |
|
173 | + if (isset($config['enabled']) && $config['enabled'] === '0') { |
|
174 | 174 | continue; |
175 | 175 | } |
176 | 176 | |
@@ -193,11 +193,11 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function getParam(string $name, string $param) |
195 | 195 | { |
196 | - if(!isset($this->config[$name]) && !isset($this->config[$name]['options'])) { |
|
196 | + if (!isset($this->config[$name]) && !isset($this->config[$name]['options'])) { |
|
197 | 197 | throw new Exception('no configuration available for service '.$name); |
198 | 198 | } |
199 | 199 | |
200 | - if(!isset($this->config[$name]['options'][$param])) { |
|
200 | + if (!isset($this->config[$name]['options'][$param])) { |
|
201 | 201 | throw new Exception('no configuration available for service parameter '.$param); |
202 | 202 | } |
203 | 203 |