| @@ 10-34 (lines=25) @@ | ||
| 7 | /** |
|
| 8 | * @author matthijs |
|
| 9 | */ |
|
| 10 | class AllowedSchemeFilter implements PreFetchFilter |
|
| 11 | { |
|
| 12 | private $allowedSchemes = array(); |
|
| 13 | ||
| 14 | /** |
|
| 15 | * @param string[] $schemes |
|
| 16 | */ |
|
| 17 | public function __construct(array $schemes) |
|
| 18 | { |
|
| 19 | $this->allowedSchemes = $schemes; |
|
| 20 | } |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @return bool |
|
| 24 | */ |
|
| 25 | public function match(FilterableUri $uri) |
|
| 26 | { |
|
| 27 | $scheme = $uri->getScheme(); |
|
| 28 | if (!in_array($scheme, $this->allowedSchemes)) { |
|
| 29 | $uri->setFiltered(true, 'Scheme not allowed'); |
|
| 30 | return true; |
|
| 31 | } |
|
| 32 | return false; |
|
| 33 | } |
|
| 34 | } |
|
| 35 | ||
| @@ 10-32 (lines=23) @@ | ||
| 7 | /** |
|
| 8 | * @author matthijs |
|
| 9 | */ |
|
| 10 | class UriFilter implements PreFetchFilter |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var array An array of regexes |
|
| 14 | */ |
|
| 15 | public $regexes = array(); |
|
| 16 | ||
| 17 | public function __construct(array $regexes = array()) |
|
| 18 | { |
|
| 19 | $this->regexes = $regexes; |
|
| 20 | } |
|
| 21 | ||
| 22 | public function match(FilterableUri $uri) |
|
| 23 | { |
|
| 24 | foreach ($this->regexes as $regex) { |
|
| 25 | if (preg_match($regex, $uri->toString())) { |
|
| 26 | $uri->setFiltered(true, "Matched URI regex '$regex'"); |
|
| 27 | return true; |
|
| 28 | } |
|
| 29 | } |
|
| 30 | return false; |
|
| 31 | } |
|
| 32 | } |
|
| 33 | ||