1 | <?php |
||
12 | class Www |
||
13 | { |
||
14 | use Utils\RedirectTrait; |
||
15 | |||
16 | /** |
||
17 | * @var bool Add or remove www |
||
18 | */ |
||
19 | private $addWww; |
||
20 | |||
21 | /** |
||
22 | * Configure whether the www subdomain should be added or removed. |
||
23 | * |
||
24 | * @param bool $addWww |
||
25 | */ |
||
26 | public function __construct($addWww = false) |
||
30 | |||
31 | /** |
||
32 | * Execute the middleware. |
||
33 | * |
||
34 | * @param RequestInterface $request |
||
35 | * @param ResponseInterface $response |
||
36 | * @param callable $next |
||
37 | * |
||
38 | * @return ResponseInterface |
||
39 | */ |
||
40 | public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next) |
||
60 | |||
61 | /** |
||
62 | * Check whether the domain can add a www. subdomain. |
||
63 | * Returns false if: |
||
64 | * - the host is "localhost" |
||
65 | * - the host is a ip |
||
66 | * - the host has already a subdomain, for example "subdomain.example.com". |
||
67 | * |
||
68 | * @param string $host |
||
69 | * |
||
70 | * @return bool |
||
71 | */ |
||
72 | private function canAddWww($host) |
||
97 | } |
||
98 |