Conditions | 6 |
Paths | 4 |
Total Lines | 27 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
26 | public function __invoke(Request $request, Response $response, $next) |
||
27 | { |
||
28 | $route = $request->getAttribute('route'); |
||
29 | |||
30 | $methods = []; |
||
31 | if (empty($route)) { |
||
32 | // Methods holds all of the HTTP Verbs that a particular route handles. |
||
33 | $methods[] = $request->getMethod(); |
||
34 | } else { |
||
35 | $pattern = $route->getPattern(); |
||
36 | |||
37 | $router = $this->container->get('router'); |
||
38 | foreach ($router->getRoutes() as $route) { |
||
39 | if ($pattern === $route->getPattern()) { |
||
40 | $methods = array_merge_recursive($methods, $route->getMethods()); |
||
41 | } |
||
42 | } |
||
43 | } |
||
44 | |||
45 | if ($next && is_callable($next)) { |
||
46 | $response = $next($request, $response); |
||
47 | } |
||
48 | |||
49 | return $response |
||
50 | ->withHeader('Access-Control-Allow-Origin', '*') |
||
51 | ->withHeader('Access-Control-Allow-Headers', implode(',', self::HEADERS)) |
||
52 | ->withHeader('Access-Control-Allow-Methods', implode(',', $methods)); |
||
53 | } |
||
55 |