@@ -220,7 +220,7 @@ |
||
220 | 220 | /** |
221 | 221 | * Set clas |
222 | 222 | * |
223 | - * @param string|object $class |
|
223 | + * @param string $class |
|
224 | 224 | * @return Route |
225 | 225 | */ |
226 | 226 | public function setClass($class): Route |
@@ -118,12 +118,12 @@ |
||
118 | 118 | * @param ContainerInterface $container |
119 | 119 | * @return array |
120 | 120 | */ |
121 | - public function getCallable(?ContainerInterface $container=null): array |
|
121 | + public function getCallable(?ContainerInterface $container = null) : array |
|
122 | 122 | { |
123 | 123 | if (is_object($this->class)) { |
124 | 124 | $instance = $this->class; |
125 | 125 | } else { |
126 | - if($container === null) { |
|
126 | + if ($container === null) { |
|
127 | 127 | $instance = new $this->class(); |
128 | 128 | } else { |
129 | 129 | $instance = $container->get($this->class); |
@@ -107,7 +107,7 @@ |
||
107 | 107 | if (count($simplexml_child->children()) === 0) { |
108 | 108 | if (!isset($simplexml_to->{$simplexml_child->getName()})) { |
109 | 109 | $simplexml_to->addChild($simplexml_child->getName(), htmlspecialchars((string)$simplexml_child)); |
110 | - } elseif($replace === true && count($simplexml_to->{$simplexml_child->getName()}->children()) === 0) { |
|
110 | + } elseif ($replace === true && count($simplexml_to->{$simplexml_child->getName()}->children()) === 0) { |
|
111 | 111 | $simplexml_to->{$simplexml_child->getName()} = htmlspecialchars((string)$simplexml_child); |
112 | 112 | } |
113 | 113 | } else { |
@@ -82,7 +82,7 @@ |
||
82 | 82 | |
83 | 83 | switch ($value['type']) { |
84 | 84 | case 'array': |
85 | - $arr = (array)$data[$value['attr']]; |
|
85 | + $arr = (array)$data[$value['attr']]; |
|
86 | 86 | unset($arr['count']); |
87 | 87 | $attrs[$attr] = $arr; |
88 | 88 | break; |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @param Iterable $config |
71 | 71 | * @return Log |
72 | 72 | */ |
73 | - public function setOptions(? Iterable $config = null): Log |
|
73 | + public function setOptions(? Iterable $config = null) : Log |
|
74 | 74 | { |
75 | 75 | if ($config === null) { |
76 | 76 | return $this; |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | |
79 | 79 | foreach ($config as $option => $value) { |
80 | 80 | if (!isset($value['enabled']) || $value['enabled'] === '1') { |
81 | - if(!isset($value['class'])) { |
|
81 | + if (!isset($value['class'])) { |
|
82 | 82 | throw new Exception('class option is requred'); |
83 | 83 | } |
84 | 84 | |
85 | - if(isset($value['config'])) { |
|
85 | + if (isset($value['config'])) { |
|
86 | 86 | $config = $value['config']; |
87 | 87 | } else { |
88 | 88 | $config = null; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function removeHeader(string $header): Response |
111 | 111 | { |
112 | - if(isset($this->headers[$header])) { |
|
112 | + if (isset($this->headers[$header])) { |
|
113 | 113 | unset($this->headers[$header]); |
114 | 114 | } |
115 | 115 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $this->terminate(); |
213 | 213 | } |
214 | 214 | |
215 | - if($this->body instanceof Closure) { |
|
215 | + if ($this->body instanceof Closure) { |
|
216 | 216 | $body = $this->body->call($this); |
217 | 217 | } else { |
218 | 218 | $body = $this->body; |
@@ -368,14 +368,14 @@ discard block |
||
368 | 368 | * @param string $format |
369 | 369 | * @return Response |
370 | 370 | */ |
371 | - public function setOutputFormat(?string $format=null): Response |
|
371 | + public function setOutputFormat(?string $format = null) : Response |
|
372 | 372 | { |
373 | - if($format === null) { |
|
373 | + if ($format === null) { |
|
374 | 374 | $this->output_format = null; |
375 | 375 | return $this->removeHeader('Content-Type'); |
376 | 376 | } |
377 | 377 | |
378 | - if(!array_key_exists($format, self::OUTPUT_FORMATS)) { |
|
378 | + if (!array_key_exists($format, self::OUTPUT_FORMATS)) { |
|
379 | 379 | throw new Exception('invalid output format given'); |
380 | 380 | } |
381 | 381 |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param Iterable $config |
34 | 34 | * @return void |
35 | 35 | */ |
36 | - public function __construct(LoggerInterface $logger, ?Iterable $config=null) |
|
36 | + public function __construct(LoggerInterface $logger, ?Iterable $config = null) |
|
37 | 37 | { |
38 | 38 | $this->logger = $logger; |
39 | 39 | $this->setOptions($config); |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * @param string $username |
125 | 125 | * @return array |
126 | 126 | */ |
127 | - protected abstract function findIdentity(string $username): ?array; |
|
127 | + protected abstract function findIdentity(string $username): ? array; |
|
128 | 128 | |
129 | 129 | |
130 | 130 | /** |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | { |
204 | 204 | if($this->token_validation_url) { |
205 | 205 | $this->logger->debug('validate oauth2 token via rfc7662 token validation endpoint ['.$this->token_validation_url.']', [ |
206 | - 'category' => get_class($this), |
|
206 | + 'category' => get_class($this), |
|
207 | 207 | ]); |
208 | 208 | |
209 | 209 | $url = str_replace('{token}', $token, $this->token_validation_url); |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | } |
215 | 215 | |
216 | 216 | $this->logger->debug('validate token via openid-connect userinfo_endpoint ['.$discovery['userinfo_endpoint'].']', [ |
217 | - 'category' => get_class($this), |
|
217 | + 'category' => get_class($this), |
|
218 | 218 | ]); |
219 | 219 | |
220 | 220 | $url = $discovery['userinfo_endpoint'].'?access_token='.$token; |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | if($code === 200) { |
232 | 232 | $attributes = json_decode($result, true); |
233 | 233 | $this->logger->debug('successfully verified oauth2 access token via authorization server', [ |
234 | - 'category' => get_class($this), |
|
234 | + 'category' => get_class($this), |
|
235 | 235 | ]); |
236 | 236 | |
237 | 237 | if(!isset($attributes[$this->identity_attribute])) { |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | return true; |
250 | 250 | } else { |
251 | 251 | $this->logger->error('failed verify oauth2 access token via authorization server, received status ['.$code.']', [ |
252 | - 'category' => get_class($this), |
|
252 | + 'category' => get_class($this), |
|
253 | 253 | ]); |
254 | 254 | |
255 | 255 | throw new Exception('failed verify oauth2 access token via authorization server'); |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | $this->logger->debug('fetch user attributes from userinfo_endpoint ['.$discovery['userinfo_endpoint'].']', [ |
277 | - 'category' => get_class($this), |
|
277 | + 'category' => get_class($this), |
|
278 | 278 | ]); |
279 | 279 | |
280 | 280 | $url = $discovery['userinfo_endpoint'].'?access_token='.$this->access_token; |
@@ -289,13 +289,13 @@ discard block |
||
289 | 289 | if($code === 200) { |
290 | 290 | $attributes = json_decode($result, true); |
291 | 291 | $this->logger->debug('successfully requested user attributes from userinfo_endpoint', [ |
292 | - 'category' => get_class($this), |
|
292 | + 'category' => get_class($this), |
|
293 | 293 | ]); |
294 | 294 | |
295 | 295 | return $this->attributes = $attributes; |
296 | 296 | } else { |
297 | 297 | $this->logger->error('failed requesting user attributes from userinfo_endpoint, status code ['.$code.']', [ |
298 | - 'category' => get_class($this), |
|
298 | + 'category' => get_class($this), |
|
299 | 299 | ]); |
300 | 300 | |
301 | 301 | throw new Exception('failed requesting user attribute from userinfo_endpoint'); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @param Iterable $config |
70 | 70 | * @return void |
71 | 71 | */ |
72 | - public function __construct(LoggerInterface $logger, ?Iterable $config=null) |
|
72 | + public function __construct(LoggerInterface $logger, ?Iterable $config = null) |
|
73 | 73 | { |
74 | 74 | $this->logger = $logger; |
75 | 75 | $this->setOptions($config); |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | return $this; |
89 | 89 | } |
90 | 90 | |
91 | - foreach($config as $option => $value) { |
|
92 | - switch($option) { |
|
91 | + foreach ($config as $option => $value) { |
|
92 | + switch ($option) { |
|
93 | 93 | case 'provider_url': |
94 | 94 | case 'token_validation_url': |
95 | 95 | case 'identity_attribute': |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
171 | 171 | curl_close($ch); |
172 | 172 | |
173 | - if($code === 200) { |
|
173 | + if ($code === 200) { |
|
174 | 174 | $discovery = json_decode($result, true); |
175 | 175 | $this->logger->debug('received openid-connect discovery document from ['.$url.']', [ |
176 | 176 | 'category' => get_class($this), |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | */ |
202 | 202 | protected function verifyToken(string $token): bool |
203 | 203 | { |
204 | - if($this->token_validation_url) { |
|
204 | + if ($this->token_validation_url) { |
|
205 | 205 | $this->logger->debug('validate oauth2 token via rfc7662 token validation endpoint ['.$this->token_validation_url.']', [ |
206 | 206 | 'category' => get_class($this), |
207 | 207 | ]); |
@@ -228,19 +228,19 @@ discard block |
||
228 | 228 | curl_close($ch); |
229 | 229 | $response = json_decode($result, true); |
230 | 230 | |
231 | - if($code === 200) { |
|
231 | + if ($code === 200) { |
|
232 | 232 | $attributes = json_decode($result, true); |
233 | 233 | $this->logger->debug('successfully verified oauth2 access token via authorization server', [ |
234 | 234 | 'category' => get_class($this), |
235 | 235 | ]); |
236 | 236 | |
237 | - if(!isset($attributes[$this->identity_attribute])) { |
|
237 | + if (!isset($attributes[$this->identity_attribute])) { |
|
238 | 238 | throw new Exception('identity attribute '.$this->identity_attribute.' not found in oauth2 response'); |
239 | 239 | } |
240 | 240 | |
241 | 241 | $this->identifier = $attributes['preferred_username']; |
242 | 242 | |
243 | - if($this->token_validation_url) { |
|
243 | + if ($this->token_validation_url) { |
|
244 | 244 | $this->attributes = $attributes; |
245 | 245 | } else { |
246 | 246 | $this->access_token = $token; |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | */ |
265 | 265 | public function getAttributes(): array |
266 | 266 | { |
267 | - if(count($this->attributes) !== 0) { |
|
267 | + if (count($this->attributes) !== 0) { |
|
268 | 268 | return $this->attributes; |
269 | 269 | } |
270 | 270 | |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | curl_close($ch); |
287 | 287 | $response = json_decode($result, true); |
288 | 288 | |
289 | - if($code === 200) { |
|
289 | + if ($code === 200) { |
|
290 | 290 | $attributes = json_decode($result, true); |
291 | 291 | $this->logger->debug('successfully requested user attributes from userinfo_endpoint', [ |
292 | 292 | 'category' => get_class($this), |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | foreach($config as $name => $service) { |
72 | 72 | if(isset($service['name']) && $parent === null) { |
73 | 73 | $id = $service['name']; |
74 | - } else { |
|
74 | + } else { |
|
75 | 75 | if($parent === null) { |
76 | 76 | $id = $name; |
77 | 77 | } else { |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | } else { |
230 | 230 | $type_class = $type->getName(); |
231 | 231 | $args[$param_name] = $this->findParentService($name, $type_class); |
232 | - } |
|
232 | + } |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | return $this->createInstance($name, $reflection, $args); |
@@ -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->flattenConfig($config); |
54 | 54 | $container = $this; |
@@ -65,14 +65,14 @@ discard block |
||
65 | 65 | * @param string $parent |
66 | 66 | * @return array |
67 | 67 | */ |
68 | - protected function flattenConfig(Iterable $config, ?string $parent=null): array |
|
68 | + protected function flattenConfig(Iterable $config, ?string $parent = null) : array |
|
69 | 69 | { |
70 | 70 | $flat = []; |
71 | - foreach($config as $name => $service) { |
|
72 | - if(isset($service['name']) && $parent === null) { |
|
71 | + foreach ($config as $name => $service) { |
|
72 | + if (isset($service['name']) && $parent === null) { |
|
73 | 73 | $id = $service['name']; |
74 | 74 | } else { |
75 | - if($parent === null) { |
|
75 | + if ($parent === null) { |
|
76 | 76 | $id = $name; |
77 | 77 | } else { |
78 | 78 | $id = $parent.'.'.$name; |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | |
86 | 86 | $new_parent = $parent.'.'.$name; |
87 | 87 | |
88 | - foreach($service as $option => $value) { |
|
89 | - switch($option) { |
|
88 | + foreach ($service as $option => $value) { |
|
89 | + switch ($option) { |
|
90 | 90 | |
91 | 91 | case 'name' : |
92 | 92 | case 'use' : |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | //$parent = $parent.'.'.$name; |
103 | 103 | $services = $this->flattenConfig($service['service'], $new_parent); |
104 | 104 | $flat[$id]['service'] = []; |
105 | - foreach($services as $key => $sub) { |
|
105 | + foreach ($services as $key => $sub) { |
|
106 | 106 | $flat[$id]['service'][$sub['name']] = $key; |
107 | 107 | } |
108 | 108 | break; |
@@ -141,10 +141,10 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function get($name) |
143 | 143 | { |
144 | - if($this->has($name)) { |
|
144 | + if ($this->has($name)) { |
|
145 | 145 | return $this->service[$name]; |
146 | 146 | } else { |
147 | - if(isset($this->registry[$name])) { |
|
147 | + if (isset($this->registry[$name])) { |
|
148 | 148 | $this->service[$name] = $this->registry[$name]->call($this); |
149 | 149 | unset($this->registry[$name]); |
150 | 150 | return $this->service[$name]; |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | */ |
164 | 164 | public function getNew(string $name) |
165 | 165 | { |
166 | - if(isset($this->registry[$name])) { |
|
166 | + if (isset($this->registry[$name])) { |
|
167 | 167 | return $this->registry[$name]->call($this); |
168 | 168 | } else { |
169 | 169 | return $this->autoWire($name); |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | */ |
181 | 181 | public function add(string $name, Closure $service): Container |
182 | 182 | { |
183 | - if($this->has($name)) { |
|
183 | + if ($this->has($name)) { |
|
184 | 184 | throw new Exception('service '.$name.' is already registered'); |
185 | 185 | } |
186 | 186 | |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | */ |
209 | 209 | protected function autoWire(string $name) |
210 | 210 | { |
211 | - if(isset($this->config[$name]['use'])) { |
|
211 | + if (isset($this->config[$name]['use'])) { |
|
212 | 212 | $class = $this->config[$name]['use']; |
213 | - } elseif(isset($this->config[$name]['name'])) { |
|
213 | + } elseif (isset($this->config[$name]['name'])) { |
|
214 | 214 | $class = $this->config[$name]['name']; |
215 | 215 | } else { |
216 | 216 | $class = $name; |
@@ -218,27 +218,27 @@ discard block |
||
218 | 218 | |
219 | 219 | try { |
220 | 220 | $reflection = new ReflectionClass($class); |
221 | - } catch(\Exception $e) { |
|
221 | + } catch (\Exception $e) { |
|
222 | 222 | throw new Exception($class.' can not be resolved to an existing class'); |
223 | 223 | } |
224 | 224 | |
225 | 225 | $constructor = $reflection->getConstructor(); |
226 | 226 | |
227 | - if($constructor === null) { |
|
227 | + if ($constructor === null) { |
|
228 | 228 | return new $class(); |
229 | 229 | } else { |
230 | 230 | $params = $constructor->getParameters(); |
231 | 231 | $args = []; |
232 | 232 | |
233 | - foreach($params as $param) { |
|
233 | + foreach ($params as $param) { |
|
234 | 234 | $type = $param->getClass(); |
235 | 235 | $param_name = $param->getName(); |
236 | 236 | |
237 | - if($type === null) { |
|
237 | + if ($type === null) { |
|
238 | 238 | try { |
239 | 239 | $args[$param_name] = $this->getParam($name, $param_name); |
240 | - } catch(Exception $e) { |
|
241 | - if($param->isDefaultValueAvailable()) { |
|
240 | + } catch (Exception $e) { |
|
241 | + if ($param->isDefaultValueAvailable()) { |
|
242 | 242 | $args[$param_name] = $param->getDefaultValue(); |
243 | 243 | } else { |
244 | 244 | throw $e; |
@@ -264,9 +264,9 @@ discard block |
||
264 | 264 | */ |
265 | 265 | protected function findParentService(string $name, string $class) |
266 | 266 | { |
267 | - if(isset($this->config[$name]['service'][$class])) { |
|
267 | + if (isset($this->config[$name]['service'][$class])) { |
|
268 | 268 | return $this->get($this->config[$name]['service'][$class]); |
269 | - } elseif(isset($this->config[$name]['parent'])) { |
|
269 | + } elseif (isset($this->config[$name]['parent'])) { |
|
270 | 270 | return $this->findParentService($this->config[$name]['parent'], $class); |
271 | 271 | } else { |
272 | 272 | return $this->get($class); |
@@ -285,14 +285,14 @@ discard block |
||
285 | 285 | protected function createInstance(string $name, ReflectionClass $class, array $args) |
286 | 286 | { |
287 | 287 | $instance = $class->newInstanceArgs($args); |
288 | - if($instance instanceof AdapterAwareInterface) { |
|
289 | - if(isset($this->config[$name]['adapter'])) { |
|
290 | - foreach($this->config[$name]['adapter'] as $adapter => $config) { |
|
291 | - if(!isset($config['name'])) { |
|
288 | + if ($instance instanceof AdapterAwareInterface) { |
|
289 | + if (isset($this->config[$name]['adapter'])) { |
|
290 | + foreach ($this->config[$name]['adapter'] as $adapter => $config) { |
|
291 | + if (!isset($config['name'])) { |
|
292 | 292 | throw new Exception('adapter requires name configuration'); |
293 | 293 | } |
294 | 294 | |
295 | - if(isset($config['enabled']) && $config['enabled'] === '0') { |
|
295 | + if (isset($config['enabled']) && $config['enabled'] === '0') { |
|
296 | 296 | continue; |
297 | 297 | } |
298 | 298 | |
@@ -315,11 +315,11 @@ discard block |
||
315 | 315 | */ |
316 | 316 | public function getParam(string $name, string $param) |
317 | 317 | { |
318 | - if(!isset($this->config[$name]) && !isset($this->config[$name]['options'])) { |
|
318 | + if (!isset($this->config[$name]) && !isset($this->config[$name]['options'])) { |
|
319 | 319 | throw new Exception('no configuration available for service '.$name); |
320 | 320 | } |
321 | 321 | |
322 | - if(!isset($this->config[$name]['options'][$param])) { |
|
322 | + if (!isset($this->config[$name]['options'][$param])) { |
|
323 | 323 | throw new Exception('no configuration available for service parameter '.$param); |
324 | 324 | } |
325 | 325 |
@@ -68,12 +68,12 @@ discard block |
||
68 | 68 | * @param array $request |
69 | 69 | * @return void |
70 | 70 | */ |
71 | - public function __construct(LoggerInterface $logger, ?array $request=null, ?ContainerInterface $container=null) |
|
71 | + public function __construct(LoggerInterface $logger, ? array $request = null, ?ContainerInterface $container = null) |
|
72 | 72 | { |
73 | 73 | $this->logger = $logger; |
74 | 74 | $this->container = $container; |
75 | 75 | |
76 | - if($request === null) { |
|
76 | + if ($request === null) { |
|
77 | 77 | $request = $_SERVER; |
78 | 78 | } |
79 | 79 | |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | 'code' => $exception->getCode() |
287 | 287 | ]; |
288 | 288 | |
289 | - if(defined("$class::HTTP_CODE")) { |
|
289 | + if (defined("$class::HTTP_CODE")) { |
|
290 | 290 | $http_code = $class::HTTP_CODE; |
291 | 291 | } else { |
292 | 292 | $http_code = 500; |