| Total Complexity | 8 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class Cors |
||
| 10 | { |
||
| 11 | const HEADERS = [ |
||
| 12 | 'Content-Type', |
||
| 13 | 'Accept', |
||
| 14 | 'Origin', |
||
| 15 | 'Authorization', |
||
| 16 | 'X-Requested-With' |
||
| 17 | ]; |
||
| 18 | |||
| 19 | protected $container; |
||
| 20 | |||
| 21 | public function __construct(ContainerInterface $container) |
||
| 24 | } |
||
| 25 | |||
| 26 | public function __invoke(Request $request, Response $response, $next) |
||
| 27 | { |
||
| 28 | if ($next && is_callable($next)) { |
||
| 29 | $response = $next($request, $response); |
||
| 30 | } |
||
| 31 | |||
| 32 | $methods = $this->methods($request); |
||
| 33 | |||
| 34 | return $response |
||
| 35 | ->withHeader('Access-Control-Allow-Origin', '*') |
||
| 36 | ->withHeader('Access-Control-Allow-Headers', implode(',', self::HEADERS)) |
||
| 37 | ->withHeader('Access-Control-Allow-Methods', implode(',', $methods)); |
||
| 38 | } |
||
| 39 | |||
| 40 | private function methods(Request $request): array |
||
| 58 | } |
||
| 59 | } |
||
| 60 |