1 | <?php declare(strict_types = 1); |
||
34 | class CorsMiddleware |
||
35 | { |
||
36 | /** |
||
37 | * @var AnalyzerInterface |
||
38 | */ |
||
39 | private $analyzer; |
||
40 | |||
41 | /** |
||
42 | * @var ContainerInterface |
||
43 | */ |
||
44 | private $container; |
||
45 | |||
46 | /** |
||
47 | * @param AnalyzerInterface $analyzer |
||
48 | 4 | * @param ContainerInterface $container |
|
49 | */ |
||
50 | 4 | public function __construct(AnalyzerInterface $analyzer, ContainerInterface $container) |
|
55 | |||
56 | /** |
||
57 | * Handle an incoming request. |
||
58 | * |
||
59 | * @param Request $request |
||
60 | * @param Closure $next |
||
61 | * |
||
62 | 4 | * @return mixed |
|
63 | */ |
||
64 | 4 | public function handle(Request $request, Closure $next) |
|
94 | |||
95 | /** |
||
96 | * You can override this method in order to customize error reply. |
||
97 | * |
||
98 | * @param AnalysisResultInterface $analysisResult |
||
99 | * |
||
100 | 1 | * @return Response |
|
101 | */ |
||
102 | protected function getResponseOnError(AnalysisResultInterface $analysisResult): Response |
||
109 | |||
110 | /** |
||
111 | * This method saves analysis result in Illuminate Container for |
||
112 | * using it in other parts of the application (e.g. in exception handler). |
||
113 | * |
||
114 | * @param Request $request |
||
115 | * |
||
116 | 4 | * @return AnalysisResultInterface |
|
117 | */ |
||
118 | 4 | protected function getCorsAnalysis(Request $request): AnalysisResultInterface |
|
125 | |||
126 | /** |
||
127 | * You can override this method to replace IlluminateRequestToPsr7 adapter with another one. |
||
128 | * |
||
129 | * @param Request $request |
||
130 | * |
||
131 | 4 | * @return RequestInterface |
|
132 | */ |
||
133 | 4 | protected function getRequestAdapter(Request $request): RequestInterface |
|
137 | |||
138 | /** |
||
139 | * There is an issue with IE which cannot work with multiple 'Access-Control-Expose-Headers' and |
||
140 | * requires it them to be comma separated. Chrome and Firefox seem to be not affected. |
||
141 | * |
||
142 | * @param array $headers |
||
143 | * |
||
144 | * @return array |
||
145 | * |
||
146 | 2 | * @see https://github.com/neomerx/cors-psr7/issues/31 |
|
147 | */ |
||
148 | 2 | protected function getPrepareCorsHeaders(array $headers): array |
|
157 | } |
||
158 |