1 | <?php |
||
12 | class Www |
||
13 | { |
||
14 | use Utils\RedirectTrait; |
||
15 | |||
16 | /** |
||
17 | * @var bool Add or remove www |
||
18 | */ |
||
19 | protected $addWww; |
||
20 | |||
21 | /** |
||
22 | * Constructor. Configure whether add or remove www. |
||
23 | * |
||
24 | * @param bool $addWww |
||
25 | */ |
||
26 | public function __construct($addWww = false) |
||
30 | |||
31 | /** |
||
32 | * Configure whether the www subdomain should be added or removed. |
||
33 | * |
||
34 | * @param bool $addWww |
||
35 | * |
||
36 | * @return self |
||
37 | */ |
||
38 | public function addWww($addWww) |
||
44 | |||
45 | /** |
||
46 | * Execute the middleware. |
||
47 | * |
||
48 | * @param RequestInterface $request |
||
49 | * @param ResponseInterface $response |
||
50 | * @param callable $next |
||
51 | * |
||
52 | * @return ResponseInterface |
||
53 | */ |
||
54 | public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next) |
||
74 | |||
75 | /** |
||
76 | * Check whether the domain can add a www. subdomain. |
||
77 | * Returns false if: |
||
78 | * - the host is "localhost" |
||
79 | * - the host is a ip |
||
80 | * - the host has already a subdomain, for example "subdomain.example.com". |
||
81 | * |
||
82 | * @param string $host |
||
83 | * |
||
84 | * @return bool |
||
85 | */ |
||
86 | public function canAddWww($host) |
||
111 | } |
||
112 |