@@ -81,7 +81,7 @@ |
||
81 | 81 | |
82 | 82 | $this->headers['content-description'] = ['File Transfer']; |
83 | 83 | $this->headers['content-type'] = [$mimetype]; |
84 | - $this->headers['content-disposition'] = ['attachment; filename="' . $filename . '"']; |
|
84 | + $this->headers['content-disposition'] = ['attachment; filename="' . $filename . '"']; |
|
85 | 85 | $this->headers['expires'] = ['0']; |
86 | 86 | $this->headers['cache-control'] = ['must-revalidate']; |
87 | 87 | $this->headers['pragma'] = ['public']; |
@@ -55,25 +55,23 @@ |
||
55 | 55 | * @class FileResponse |
56 | 56 | * @package Platine\Framework\Http\Response |
57 | 57 | */ |
58 | -class FileResponse extends Response |
|
59 | -{ |
|
58 | +class FileResponse extends Response { |
|
60 | 59 | /** |
61 | 60 | * Create new instance |
62 | 61 | * @param string $path |
63 | 62 | * @param string|null $filename |
64 | 63 | */ |
65 | - public function __construct(string $path, ?string $filename = null) |
|
66 | - { |
|
64 | + public function __construct(string $path, ?string $filename = null) { |
|
67 | 65 | parent::__construct(200); |
68 | 66 | |
69 | 67 | $realpath = Path::realPath($path); |
70 | 68 | $extension = pathinfo($realpath, PATHINFO_EXTENSION); |
71 | 69 | $mimetype = 'application/octet-stream'; |
72 | - if (!empty($extension)) { |
|
70 | + if (!empty($extension)) { |
|
73 | 71 | $mimetype = Path::getMimeByExtension($extension); |
74 | 72 | } |
75 | 73 | |
76 | - if (empty($filename)) { |
|
74 | + if (empty($filename)) { |
|
77 | 75 | $filename = basename($realpath); |
78 | 76 | } |
79 | 77 |
@@ -54,8 +54,7 @@ discard block |
||
54 | 54 | * @class TemplateResponse |
55 | 55 | * @package Platine\Framework\Http\Response |
56 | 56 | */ |
57 | -class TemplateResponse extends Response |
|
58 | -{ |
|
57 | +class TemplateResponse extends Response { |
|
59 | 58 | /** |
60 | 59 | * The template instance |
61 | 60 | * @var Template |
@@ -76,7 +75,7 @@ discard block |
||
76 | 75 | array $context = [], |
77 | 76 | int $statusCode = 200, |
78 | 77 | string $reasonPhrase = '' |
79 | - ) { |
|
78 | + ) { |
|
80 | 79 | parent::__construct($statusCode, $reasonPhrase); |
81 | 80 | $this->template = $template; |
82 | 81 | $this->getBody()->write($template->render($name, $context)); |
@@ -54,8 +54,7 @@ discard block |
||
54 | 54 | * @class JsonResponse |
55 | 55 | * @package Platine\Framework\Http\Response |
56 | 56 | */ |
57 | -class JsonResponse extends Response |
|
58 | -{ |
|
57 | +class JsonResponse extends Response { |
|
59 | 58 | /** |
60 | 59 | * Create new instance |
61 | 60 | * @param mixed $data |
@@ -66,7 +65,7 @@ discard block |
||
66 | 65 | $data, |
67 | 66 | int $statusCode = 200, |
68 | 67 | string $reasonPhrase = '' |
69 | - ) { |
|
68 | + ) { |
|
70 | 69 | parent::__construct($statusCode, $reasonPhrase); |
71 | 70 | |
72 | 71 | $this->headers['content-type'] = ['application/json']; |
@@ -51,8 +51,7 @@ discard block |
||
51 | 51 | * @class RestResponse |
52 | 52 | * @package Platine\Framework\Http\Response |
53 | 53 | */ |
54 | -class RestResponse extends JsonResponse |
|
55 | -{ |
|
54 | +class RestResponse extends JsonResponse { |
|
56 | 55 | /** |
57 | 56 | * Create new instance |
58 | 57 | * @param mixed $data |
@@ -71,20 +70,20 @@ discard block |
||
71 | 70 | string $message = '', |
72 | 71 | int $statusCode = 200, |
73 | 72 | string $reasonPhrase = '' |
74 | - ) { |
|
73 | + ) { |
|
75 | 74 | $result = [ |
76 | 75 | 'success' => $success, |
77 | 76 | 'timestamp' => time(), |
78 | 77 | 'code' => $code, |
79 | 78 | ]; |
80 | 79 | |
81 | - if (!empty($message)) { |
|
80 | + if (!empty($message)) { |
|
82 | 81 | $result['message'] = $message; |
83 | 82 | } |
84 | 83 | |
85 | 84 | $result['data'] = $data; |
86 | 85 | |
87 | - if (!empty($extras)) { |
|
86 | + if (!empty($extras)) { |
|
88 | 87 | $result = array_merge($result, $extras); |
89 | 88 | } |
90 | 89 |
@@ -55,8 +55,7 @@ discard block |
||
55 | 55 | * @class RouteHelper |
56 | 56 | * @package Platine\Framework\Http |
57 | 57 | */ |
58 | -class RouteHelper |
|
59 | -{ |
|
58 | +class RouteHelper { |
|
60 | 59 | /** |
61 | 60 | * The router instance |
62 | 61 | * @var Router |
@@ -67,8 +66,7 @@ discard block |
||
67 | 66 | * Create new instance |
68 | 67 | * @param Router $router |
69 | 68 | */ |
70 | - public function __construct(Router $router) |
|
71 | - { |
|
69 | + public function __construct(Router $router) { |
|
72 | 70 | $this->router = $router; |
73 | 71 | } |
74 | 72 |
@@ -59,8 +59,7 @@ discard block |
||
59 | 59 | * @class RouteDispatcherMiddleware |
60 | 60 | * @package Platine\Framework\Http\Middleware |
61 | 61 | */ |
62 | -class RouteDispatcherMiddleware implements MiddlewareInterface |
|
63 | -{ |
|
62 | +class RouteDispatcherMiddleware implements MiddlewareInterface { |
|
64 | 63 | /** |
65 | 64 | * The Middleware resolver instance |
66 | 65 | * @var MiddlewareResolverInterface |
@@ -71,8 +70,7 @@ discard block |
||
71 | 70 | * Create new instance |
72 | 71 | * @param MiddlewareResolverInterface $resolver |
73 | 72 | */ |
74 | - public function __construct(MiddlewareResolverInterface $resolver) |
|
75 | - { |
|
73 | + public function __construct(MiddlewareResolverInterface $resolver) { |
|
76 | 74 | $this->resolver = $resolver; |
77 | 75 | } |
78 | 76 | |
@@ -83,11 +81,11 @@ discard block |
||
83 | 81 | ServerRequestInterface $request, |
84 | 82 | RequestHandlerInterface $handler |
85 | 83 | ): ResponseInterface { |
86 | - if (!$result = $request->getAttribute(Route::class)) { |
|
84 | + if (!$result = $request->getAttribute(Route::class)) { |
|
87 | 85 | return $handler->handle($request); |
88 | 86 | } |
89 | 87 | |
90 | - if ($result instanceof Route) { |
|
88 | + if ($result instanceof Route) { |
|
91 | 89 | $result = $result->getHandler(); |
92 | 90 | } |
93 | 91 |
@@ -174,14 +174,14 @@ |
||
174 | 174 | { |
175 | 175 | if ($this->isPreflight()) { |
176 | 176 | $this->setOrigin() |
177 | - ->setMaxAge() |
|
178 | - ->setAllowCredentials() |
|
179 | - ->setAllowMethods() |
|
180 | - ->setAllowHeaders(); |
|
177 | + ->setMaxAge() |
|
178 | + ->setAllowCredentials() |
|
179 | + ->setAllowMethods() |
|
180 | + ->setAllowHeaders(); |
|
181 | 181 | } else { |
182 | 182 | $this->setOrigin() |
183 | - ->setExposedHeaders() |
|
184 | - ->setAllowCredentials(); |
|
183 | + ->setExposedHeaders() |
|
184 | + ->setAllowCredentials(); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 |
@@ -62,8 +62,7 @@ discard block |
||
62 | 62 | * @package Platine\Framework\Http\Middleware |
63 | 63 | * @template T |
64 | 64 | */ |
65 | -class CorsMiddleware implements MiddlewareInterface |
|
66 | -{ |
|
65 | +class CorsMiddleware implements MiddlewareInterface { |
|
67 | 66 | /** |
68 | 67 | * The configuration instance |
69 | 68 | * @var Config<T> |
@@ -96,7 +95,7 @@ discard block |
||
96 | 95 | public function __construct( |
97 | 96 | LoggerInterface $logger, |
98 | 97 | Config $config |
99 | - ) { |
|
98 | + ) { |
|
100 | 99 | $this->config = $config; |
101 | 100 | $this->logger = $logger; |
102 | 101 | } |
@@ -108,13 +107,13 @@ discard block |
||
108 | 107 | ServerRequestInterface $request, |
109 | 108 | RequestHandlerInterface $handler |
110 | 109 | ): ResponseInterface { |
111 | - if (!$this->shouldBeProcessed($request)) { |
|
110 | + if (!$this->shouldBeProcessed($request)) { |
|
112 | 111 | return $handler->handle($request); |
113 | 112 | } |
114 | 113 | |
115 | 114 | $this->request = $request; |
116 | 115 | |
117 | - if ($this->isPreflight()) { |
|
116 | + if ($this->isPreflight()) { |
|
118 | 117 | $response = new Response(204); |
119 | 118 | |
120 | 119 | $this->logger->info( |
@@ -124,7 +123,7 @@ discard block |
||
124 | 123 | 'url' => (string) $request->getUri(), |
125 | 124 | ] |
126 | 125 | ); |
127 | - } else { |
|
126 | + } else { |
|
128 | 127 | $response = $handler->handle($request); |
129 | 128 | } |
130 | 129 | $this->response = $response; |
@@ -144,13 +143,13 @@ discard block |
||
144 | 143 | //If no route has been match no need check for CORS |
145 | 144 | /** @var ?Route $route */ |
146 | 145 | $route = $request->getAttribute(Route::class); |
147 | - if (!$route) { |
|
146 | + if (!$route) { |
|
148 | 147 | return false; |
149 | 148 | } |
150 | 149 | |
151 | 150 | //Check if the path match |
152 | 151 | $path = $this->config->get('security.cors.path', '/'); |
153 | - if (!preg_match('~^' . $path . '~', $route->getPattern())) { |
|
152 | + if (!preg_match('~^' . $path . '~', $route->getPattern())) { |
|
154 | 153 | return false; |
155 | 154 | } |
156 | 155 | |
@@ -172,13 +171,13 @@ discard block |
||
172 | 171 | */ |
173 | 172 | protected function setCorsHeaders(): void |
174 | 173 | { |
175 | - if ($this->isPreflight()) { |
|
174 | + if ($this->isPreflight()) { |
|
176 | 175 | $this->setOrigin() |
177 | 176 | ->setMaxAge() |
178 | 177 | ->setAllowCredentials() |
179 | 178 | ->setAllowMethods() |
180 | 179 | ->setAllowHeaders(); |
181 | - } else { |
|
180 | + } else { |
|
182 | 181 | $this->setOrigin() |
183 | 182 | ->setExposedHeaders() |
184 | 183 | ->setAllowCredentials(); |
@@ -195,8 +194,8 @@ discard block |
||
195 | 194 | // default to the first allowed origin |
196 | 195 | $origin = reset($origins); |
197 | 196 | |
198 | - foreach ($origins as $ori) { |
|
199 | - if ($ori === $this->request->getHeaderLine('Origin')) { |
|
197 | + foreach ($origins as $ori) { |
|
198 | + if ($ori === $this->request->getHeaderLine('Origin')) { |
|
200 | 199 | $origin = $ori; |
201 | 200 | break; |
202 | 201 | } |
@@ -219,7 +218,7 @@ discard block |
||
219 | 218 | { |
220 | 219 | |
221 | 220 | $headers = $this->config->get('security.cors.expose_headers', []); |
222 | - if (!empty($headers)) { |
|
221 | + if (!empty($headers)) { |
|
223 | 222 | $this->response = $this->response |
224 | 223 | ->withHeader( |
225 | 224 | 'Access-Control-Expose-Headers', |
@@ -255,7 +254,7 @@ discard block |
||
255 | 254 | { |
256 | 255 | $allowCredentials = $this->config->get('security.cors.allow_credentials', false); |
257 | 256 | |
258 | - if ($allowCredentials) { |
|
257 | + if ($allowCredentials) { |
|
259 | 258 | $this->response = $this->response |
260 | 259 | ->withHeader( |
261 | 260 | 'Access-Control-Allow-Credential', |
@@ -274,7 +273,7 @@ discard block |
||
274 | 273 | { |
275 | 274 | $methods = $this->config->get('security.cors.allow_methods', []); |
276 | 275 | |
277 | - if (!empty($methods)) { |
|
276 | + if (!empty($methods)) { |
|
278 | 277 | $this->response = $this->response |
279 | 278 | ->withHeader( |
280 | 279 | 'Access-Control-Allow-Methods', |
@@ -294,17 +293,17 @@ discard block |
||
294 | 293 | |
295 | 294 | $headers = $this->config->get('security.cors.allow_headers', []); |
296 | 295 | |
297 | - if (empty($headers)) { |
|
296 | + if (empty($headers)) { |
|
298 | 297 | //use request headers |
299 | 298 | $requestHeaders = $this->request |
300 | 299 | ->getHeaderLine('Access-Control-Request-Headers'); |
301 | 300 | |
302 | - if (!empty($requestHeaders)) { |
|
301 | + if (!empty($requestHeaders)) { |
|
303 | 302 | $headers = $requestHeaders; |
304 | 303 | } |
305 | 304 | } |
306 | - if (!empty($headers)) { |
|
307 | - if (is_array($headers)) { |
|
305 | + if (!empty($headers)) { |
|
306 | + if (is_array($headers)) { |
|
308 | 307 | $headers = implode(', ', $headers); |
309 | 308 | } |
310 | 309 |
@@ -138,8 +138,8 @@ |
||
138 | 138 | ); |
139 | 139 | |
140 | 140 | $httpException->setTitle('Service Unavailable') |
141 | - ->setDescription($message) |
|
142 | - ->setHeaders($this->getHeaders($data)); |
|
141 | + ->setDescription($message) |
|
142 | + ->setHeaders($this->getHeaders($data)); |
|
143 | 143 | |
144 | 144 | // TODO Add headers |
145 | 145 | throw $httpException; |
@@ -71,8 +71,7 @@ discard block |
||
71 | 71 | * @package Platine\Framework\Http\Middleware |
72 | 72 | * @template T |
73 | 73 | */ |
74 | -class MaintenanceMiddleware implements MiddlewareInterface |
|
75 | -{ |
|
74 | +class MaintenanceMiddleware implements MiddlewareInterface { |
|
76 | 75 | /** |
77 | 76 | * The configuration instance |
78 | 77 | * @var Config<T> |
@@ -93,7 +92,7 @@ discard block |
||
93 | 92 | public function __construct( |
94 | 93 | Config $config, |
95 | 94 | Application $app |
96 | - ) { |
|
95 | + ) { |
|
97 | 96 | $this->config = $config; |
98 | 97 | $this->app = $app; |
99 | 98 | } |
@@ -106,26 +105,26 @@ discard block |
||
106 | 105 | RequestHandlerInterface $handler |
107 | 106 | ): ResponseInterface { |
108 | 107 | |
109 | - if ($this->isExceptUrl($request)) { |
|
108 | + if ($this->isExceptUrl($request)) { |
|
110 | 109 | return $handler->handle($request); |
111 | 110 | } |
112 | 111 | |
113 | - if ($this->app->isInMaintenance()) { |
|
114 | - try { |
|
112 | + if ($this->app->isInMaintenance()) { |
|
113 | + try { |
|
115 | 114 | $data = $this->app->maintenance()->data(); |
116 | - } catch (Throwable $ex) { |
|
115 | + } catch (Throwable $ex) { |
|
117 | 116 | throw $ex; |
118 | 117 | } |
119 | 118 | |
120 | - if (isset($data['secret']) && trim($request->getUri()->getPath(), '/') === $data['secret']) { |
|
119 | + if (isset($data['secret']) && trim($request->getUri()->getPath(), '/') === $data['secret']) { |
|
121 | 120 | return $this->bypassResponse($data['secret']); |
122 | 121 | } |
123 | 122 | |
124 | - if ($this->hasValidBypassCookie($request, $data)) { |
|
123 | + if ($this->hasValidBypassCookie($request, $data)) { |
|
125 | 124 | return $handler->handle($request); |
126 | 125 | } |
127 | 126 | |
128 | - if (isset($data['template'])) { |
|
127 | + if (isset($data['template'])) { |
|
129 | 128 | return $this->templateResponse($data['template'], $data); |
130 | 129 | } |
131 | 130 | |
@@ -179,7 +178,7 @@ discard block |
||
179 | 178 | $data['status'] ?? 503 |
180 | 179 | ); |
181 | 180 | |
182 | - foreach ($this->getHeaders($data) as $name => $value) { |
|
181 | + foreach ($this->getHeaders($data) as $name => $value) { |
|
183 | 182 | $response = $response->withAddedHeader($name, $value); |
184 | 183 | } |
185 | 184 | |
@@ -194,8 +193,8 @@ discard block |
||
194 | 193 | protected function isExceptUrl(ServerRequestInterface $request): bool |
195 | 194 | { |
196 | 195 | $path = $request->getUri()->getPath(); |
197 | - foreach ($this->getExceptUrls() as $url) { |
|
198 | - if (Str::is($url, $path)) { |
|
196 | + foreach ($this->getExceptUrls() as $url) { |
|
197 | + if (Str::is($url, $path)) { |
|
199 | 198 | return true; |
200 | 199 | } |
201 | 200 | } |
@@ -220,7 +219,7 @@ discard block |
||
220 | 219 | */ |
221 | 220 | protected function hasValidBypassCookie(ServerRequestInterface $request, array $data): bool |
222 | 221 | { |
223 | - if (!isset($data['secret'])) { |
|
222 | + if (!isset($data['secret'])) { |
|
224 | 223 | return false; |
225 | 224 | } |
226 | 225 | |
@@ -228,7 +227,7 @@ discard block |
||
228 | 227 | $secret = $data['secret']; |
229 | 228 | $name = $this->getCookieName(); |
230 | 229 | $cookieValue = (new RequestData($request))->cookie($name); |
231 | - if (empty($cookieValue)) { |
|
230 | + if (empty($cookieValue)) { |
|
232 | 231 | return false; |
233 | 232 | } |
234 | 233 | |
@@ -278,7 +277,7 @@ discard block |
||
278 | 277 | protected function getHeaders(array $data): array |
279 | 278 | { |
280 | 279 | $headers = isset($data['retry']) ? ['Retry-After' => $data['retry']] : []; |
281 | - if (isset($data['refresh'])) { |
|
280 | + if (isset($data['refresh'])) { |
|
282 | 281 | $headers['Refresh'] = $data['refresh']; |
283 | 282 | } |
284 | 283 |
@@ -116,7 +116,7 @@ |
||
116 | 116 | */ |
117 | 117 | protected function shouldBeProcessed(ServerRequestInterface $request): bool |
118 | 118 | { |
119 | - //If no route has been match no need check for CSRF |
|
119 | + //If no route has been match no need check for CSRF |
|
120 | 120 | /** @var ?Route $route */ |
121 | 121 | $route = $request->getAttribute(Route::class); |
122 | 122 | if (!$route) { |
@@ -59,8 +59,7 @@ discard block |
||
59 | 59 | * @package Platine\Framework\Http\Middleware |
60 | 60 | * @template T |
61 | 61 | */ |
62 | -class SecurityPolicyMiddleware implements MiddlewareInterface |
|
63 | -{ |
|
62 | +class SecurityPolicyMiddleware implements MiddlewareInterface { |
|
64 | 63 | /** |
65 | 64 | * The SecurityPolicy instance |
66 | 65 | * @var SecurityPolicy<T> |
@@ -71,8 +70,7 @@ discard block |
||
71 | 70 | * Create new instance |
72 | 71 | * @param SecurityPolicy<T> $securityPolicy |
73 | 72 | */ |
74 | - public function __construct(SecurityPolicy $securityPolicy) |
|
75 | - { |
|
73 | + public function __construct(SecurityPolicy $securityPolicy) { |
|
76 | 74 | $this->securityPolicy = $securityPolicy; |
77 | 75 | } |
78 | 76 | |
@@ -84,7 +82,7 @@ discard block |
||
84 | 82 | RequestHandlerInterface $handler |
85 | 83 | ): ResponseInterface { |
86 | 84 | |
87 | - if (!$this->shouldBeProcessed($request)) { |
|
85 | + if (!$this->shouldBeProcessed($request)) { |
|
88 | 86 | return $handler->handle($request); |
89 | 87 | } |
90 | 88 | |
@@ -102,7 +100,7 @@ discard block |
||
102 | 100 | $response = $handler->handle($request); |
103 | 101 | |
104 | 102 | $headers = $this->securityPolicy->headers(); |
105 | - foreach ($headers as $name => $value) { |
|
103 | + foreach ($headers as $name => $value) { |
|
106 | 104 | $response = $response->withAddedHeader($name, $value); |
107 | 105 | } |
108 | 106 | |
@@ -119,7 +117,7 @@ discard block |
||
119 | 117 | //If no route has been match no need check for CSRF |
120 | 118 | /** @var ?Route $route */ |
121 | 119 | $route = $request->getAttribute(Route::class); |
122 | - if (!$route) { |
|
120 | + if (!$route) { |
|
123 | 121 | return false; |
124 | 122 | } |
125 | 123 |