Total Complexity | 5 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
10 | class AllowedHostsFilter implements PreFetchFilterInterface |
||
11 | { |
||
12 | /** @var array The hostnames to filter links with */ |
||
13 | private $allowedHosts; |
||
14 | |||
15 | private $allowSubDomains; |
||
16 | |||
17 | /** |
||
18 | * @param string[] $seeds |
||
19 | * @param bool $allowSubDomains |
||
20 | */ |
||
21 | public function __construct(array $seeds, $allowSubDomains = false) |
||
22 | { |
||
23 | $this->allowSubDomains = $allowSubDomains; |
||
24 | |||
25 | foreach ($seeds as $seed) { |
||
26 | $hostname = parse_url($seed, PHP_URL_HOST); |
||
27 | |||
28 | if ($this->allowSubDomains) { |
||
29 | // only use hostname.tld for comparison |
||
30 | $this->allowedHosts[] = join('.', array_slice(explode('.', $hostname), -2)); |
||
31 | } else { |
||
32 | // user entire *.hostname.tld for comparison |
||
33 | $this->allowedHosts[] = $hostname; |
||
34 | } |
||
35 | } |
||
36 | } |
||
37 | |||
38 | public function match(UriInterface $uri) |
||
48 | } |
||
49 | } |
||
50 |