1 | <?php |
||
16 | class Cors |
||
17 | { |
||
18 | /** |
||
19 | * @var SettingsStrategyInterface The settings used by the Analyzer |
||
20 | */ |
||
21 | private $settings; |
||
22 | |||
23 | /** |
||
24 | * @var LoggerInterface|null The logger used by the Analyzer for debugging |
||
25 | */ |
||
26 | private $logger; |
||
27 | |||
28 | /** |
||
29 | * Defines the settings used. |
||
30 | * |
||
31 | * @param SettingsStrategyInterface|null $settings |
||
32 | */ |
||
33 | public function __construct(SettingsStrategyInterface $settings = null) |
||
37 | |||
38 | /** |
||
39 | * Set the server origin. |
||
40 | * |
||
41 | * @see Neomerx\Cors\Contracts\Strategies::setServerOrigin |
||
42 | * |
||
43 | * @param string|array $origin |
||
44 | * |
||
45 | * @return self |
||
46 | */ |
||
47 | public function origin($origin) |
||
53 | |||
54 | /** |
||
55 | * Set allowed origins. |
||
56 | * |
||
57 | * @see Neomerx\Cors\Contracts\Strategies::setRequestAllowedOrigins |
||
58 | * |
||
59 | * @param array $origins |
||
60 | * |
||
61 | * @return self |
||
62 | */ |
||
63 | public function allowedOrigins(array $origins) |
||
69 | |||
70 | /** |
||
71 | * Set allowed methods. |
||
72 | * |
||
73 | * @see Neomerx\Cors\Contracts\Strategies::setRequestAllowedMethods |
||
74 | * @see Neomerx\Cors\Contracts\Strategies::setForceAddAllowedMethodsToPreFlightResponse |
||
75 | * |
||
76 | * @param array $methods |
||
77 | * @param bool $force If allowed methods should be added to pre-flight response |
||
78 | * |
||
79 | * @return self |
||
80 | */ |
||
81 | public function allowedMethods(array $methods, $force = false) |
||
88 | |||
89 | /** |
||
90 | * Set allowed headers. |
||
91 | * |
||
92 | * @see Neomerx\Cors\Contracts\Strategies::setRequestAllowedHeaders |
||
93 | * @see Neomerx\Cors\Contracts\Strategies::setForceAddAllowedHeadersToPreFlightResponse |
||
94 | * |
||
95 | * @param array $headers |
||
96 | * @param bool $force If allowed headers should be added to pre-flight response |
||
97 | * |
||
98 | * @return self |
||
99 | */ |
||
100 | public function allowedHeaders(array $headers, $force = false) |
||
107 | |||
108 | /** |
||
109 | * Set headers other than the simple ones that might be exposed to user agent. |
||
110 | * |
||
111 | * @see Neomerx\Cors\Contracts\Strategies::setResponseExposedHeaders |
||
112 | * |
||
113 | * @param array $headers |
||
114 | * |
||
115 | * @return self |
||
116 | */ |
||
117 | public function exposedHeaders(array $headers) |
||
123 | |||
124 | /** |
||
125 | * If access with credentials is supported by the resource. |
||
126 | * |
||
127 | * @see Neomerx\Cors\Contracts\Strategies::setRequestCredentialsSupported |
||
128 | * |
||
129 | * @param bool $allow |
||
130 | * |
||
131 | * @return self |
||
132 | */ |
||
133 | public function allowCredentials($allow = true) |
||
139 | |||
140 | /** |
||
141 | * Set pre-flight cache max period in seconds. |
||
142 | * |
||
143 | * @see Neomerx\Cors\Contracts\Strategies::setPreFlightCacheMaxAge |
||
144 | * |
||
145 | * @param int $maxAge |
||
146 | * |
||
147 | * @return self |
||
148 | */ |
||
149 | public function maxAge($maxAge) |
||
155 | |||
156 | /** |
||
157 | * If request 'Host' header should be checked against server's origin. |
||
158 | * |
||
159 | * @see Neomerx\Cors\Contracts\Strategies::setCheckHost |
||
160 | * |
||
161 | * @param bool $checkHost |
||
162 | * |
||
163 | * @return self |
||
164 | */ |
||
165 | public function checkHost($checkHost = true) |
||
171 | |||
172 | /** |
||
173 | * Set the logger used by the Analyzer for debugging purposes. |
||
174 | * |
||
175 | * @param LoggerInterface |
||
176 | * |
||
177 | * @return self |
||
178 | */ |
||
179 | public function logger(LoggerInterface $logger) |
||
185 | |||
186 | /** |
||
187 | * Execute the middleware. |
||
188 | * |
||
189 | * @param ServerRequestInterface $request |
||
190 | * @param ResponseInterface $response |
||
191 | * @param callable $next |
||
192 | * |
||
193 | * @return ResponseInterface |
||
194 | */ |
||
195 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
232 | } |
||
233 |