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) |
||
31 | |||
32 | /** |
||
33 | * Execute the middleware. |
||
34 | * |
||
35 | * @param ServerRequestInterface $request |
||
36 | * @param ResponseInterface $response |
||
37 | * @param callable $next |
||
38 | * |
||
39 | * @return ResponseInterface |
||
40 | */ |
||
41 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
61 | |||
62 | /** |
||
63 | * Check whether the domain can add a www. subdomain. |
||
64 | * Returns false if: |
||
65 | * - the host is "localhost" |
||
66 | * - the host is a ip |
||
67 | * - the host has already a subdomain, for example "subdomain.example.com". |
||
68 | * |
||
69 | * @param string $host |
||
70 | * |
||
71 | * @return bool |
||
72 | */ |
||
73 | private function canAddWww($host) |
||
98 | } |
||
99 |