1 | <?php |
||
21 | class Secure implements RuleInterface |
||
22 | { |
||
23 | /** |
||
24 | * |
||
25 | * Checks that the Route `$secure` matches the corresponding server values. |
||
26 | * |
||
27 | * @param ServerRequestInterface $request The HTTP request. |
||
28 | * |
||
29 | * @param Route $route The route. |
||
30 | * |
||
31 | * @return bool True on success, false on failure. |
||
32 | * |
||
33 | */ |
||
34 | 8 | public function __invoke(ServerRequestInterface $request, Route $route) |
|
35 | { |
||
36 | 8 | if ($route->secure === null) { |
|
37 | 5 | return true; |
|
38 | } |
||
39 | |||
40 | 3 | $server = $request->getServerParams(); |
|
41 | 3 | $secure = $this->https($server) || $this->port443($server) || $this->forwarded($server); |
|
42 | 3 | return $route->secure == $secure; |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * |
||
47 | * Is HTTPS on? |
||
48 | * |
||
49 | * @param array $server The server params. |
||
50 | * |
||
51 | * @return bool |
||
52 | * |
||
53 | */ |
||
54 | 3 | protected function https($server) |
|
59 | |||
60 | |||
61 | /** |
||
62 | * |
||
63 | * Is the request on port 443? |
||
64 | * |
||
65 | * @param array $server The server params. |
||
66 | * |
||
67 | * @return bool |
||
68 | * |
||
69 | */ |
||
70 | 3 | protected function port443($server) |
|
75 | |||
76 | /** |
||
77 | * |
||
78 | * Is X-Forwarded-Proto https? |
||
79 | * |
||
80 | * @param array $server The server params. |
||
81 | * |
||
82 | * @return bool |
||
83 | * |
||
84 | */ |
||
85 | 3 | protected function forwarded($server) |
|
90 | } |
||
91 |