1 | <?php |
||
12 | class Https |
||
13 | { |
||
14 | use Utils\RedirectTrait; |
||
15 | |||
16 | const HEADER = 'Strict-Transport-Security'; |
||
17 | |||
18 | /** |
||
19 | * @param int One year by default |
||
20 | */ |
||
21 | private $maxAge = 31536000; |
||
22 | |||
23 | /** |
||
24 | * @param bool Whether include subdomains |
||
25 | */ |
||
26 | private $includeSubdomains = false; |
||
27 | |||
28 | /** |
||
29 | * @param bool Whether check the headers "HTTP_X_FORWARDED_PROTO: https" or "HTTP_X_FORWARDED_PORT: 443" |
||
30 | */ |
||
31 | private $checkHttpsForward = false; |
||
32 | |||
33 | /** |
||
34 | * Set basic config. |
||
35 | */ |
||
36 | public function __construct() |
||
40 | |||
41 | /** |
||
42 | * Configure the max-age HSTS in seconds. |
||
43 | * |
||
44 | * @param int $maxAge |
||
45 | * |
||
46 | * @return self |
||
47 | */ |
||
48 | public function maxAge($maxAge) |
||
54 | |||
55 | /** |
||
56 | * Configure the includeSubDomains HSTS directive. |
||
57 | * |
||
58 | * @param bool $includeSubdomains |
||
59 | * |
||
60 | * @return self |
||
61 | */ |
||
62 | public function includeSubdomains($includeSubdomains = true) |
||
68 | |||
69 | /** |
||
70 | * Configure whether check the following headers before redirect: |
||
71 | * HTTP_X_FORWARDED_PROTO: https |
||
72 | * HTTP_X_FORWARDED_PORT: 443 |
||
73 | * |
||
74 | * @param bool $checkHttpsForward |
||
75 | * |
||
76 | * @return self |
||
77 | */ |
||
78 | public function checkHttpsForward($checkHttpsForward = true) |
||
84 | |||
85 | /** |
||
86 | * Execute the middleware. |
||
87 | * |
||
88 | * @param ServerRequestInterface $request |
||
89 | * @param ResponseInterface $response |
||
90 | * @param callable $next |
||
91 | * |
||
92 | * @return ResponseInterface |
||
93 | */ |
||
94 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
120 | } |
||
121 |