1 | <?php |
||
10 | class CORSHeaders implements MiddlewareInterface |
||
11 | { |
||
12 | const MIRROR = 'mirror'; |
||
13 | const ALL = 'all'; |
||
14 | const CUSTOM = 'custom'; |
||
15 | |||
16 | /** @var string */ |
||
17 | private $behaviour; |
||
18 | |||
19 | /** @var array */ |
||
20 | private $allowedOrigins = []; |
||
21 | |||
22 | /** @var bool */ |
||
23 | private $allowedCredentials = false; |
||
24 | |||
25 | /** |
||
26 | * @param string $behaviour |
||
27 | * @throws MiddlewareException |
||
28 | */ |
||
29 | 6 | public function __construct($behaviour = self::ALL) |
|
37 | |||
38 | /** |
||
39 | * @param array $allowedOrigins |
||
40 | * @return CORSHeaders |
||
41 | */ |
||
42 | 6 | public function allowedOrigins(array $allowedOrigins) |
|
47 | |||
48 | /** |
||
49 | * @param bool $allowCredentials |
||
50 | * @return CORSHeaders |
||
51 | */ |
||
52 | 6 | public function allowCredentials($allowCredentials = true) |
|
57 | |||
58 | /** |
||
59 | * @param Request $request |
||
60 | * @param Response $response |
||
61 | * @param callable $next |
||
62 | * @return JsonApiResponse |
||
63 | */ |
||
64 | 6 | public function __invoke(Request $request, Response $response, callable $next) |
|
86 | |||
87 | /** |
||
88 | * @param Response $response |
||
89 | * @throws MiddlewareException |
||
90 | */ |
||
91 | 2 | private function applyAll(Response $response) |
|
95 | |||
96 | /** |
||
97 | * @param Response $response |
||
98 | * @param string $origin |
||
99 | */ |
||
100 | 2 | private function applyMirror(Response $response, $origin) |
|
107 | |||
108 | /** |
||
109 | * @param Response $response |
||
110 | * @throws MiddlewareException |
||
111 | */ |
||
112 | 2 | private function applyCustom(Response $response) |
|
123 | } |
||
124 |