1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Valdi package. |
||
5 | * |
||
6 | * (c) Philip Lehmann-Böhm <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Valdi\Validator; |
||
13 | |||
14 | /** |
||
15 | * Base validator for PHPs filter_var function. |
||
16 | */ |
||
17 | abstract class AbstractFilter implements ValidatorInterface |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Gets the filter to use within the validation. |
||
22 | * See http://php.net/manual/de/filter.filters.validate.php . |
||
23 | * |
||
24 | * @return string - the filter to use |
||
25 | */ |
||
26 | abstract protected function getFilter(); |
||
27 | |||
28 | /** |
||
29 | * Gets the flags to use within the validation. |
||
30 | * See http://php.net/manual/de/filter.filters.validate.php . |
||
31 | * |
||
32 | * @return string|null - the flags to use |
||
33 | */ |
||
34 | 15 | protected function getFlags() |
|
35 | { |
||
36 | 15 | return null; |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | 17 | public function isValid($value, array $parameters) |
|
43 | { |
||
44 | 17 | return in_array($value, ['', null], true) || |
|
45 | 17 | filter_var($value, $this->getFilter(), $this->getFlags()) !== false; |
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
46 | } |
||
47 | } |
||
48 |