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
|
|
|
use Valdi\ValidationException; |
15
|
|
|
use Valdi\Validator; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Validator for array data, be it maps or lists. |
19
|
|
|
*/ |
20
|
|
|
abstract class AbstractArray implements ValidatorInterface |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Holds the invalid values. |
26
|
|
|
*/ |
27
|
|
|
protected $invalidDetails; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Checks whether the given values are of the expected array data. |
32
|
|
|
* |
33
|
|
|
* @param mixed $values the potential array values to check |
34
|
|
|
* @param Validator $validator the validator to check with |
35
|
|
|
* @param array $rules the rules which the array data must fulfill |
36
|
|
|
* |
37
|
|
|
* @return boolean - true if all the $values are valid, else false with the invalid details set |
38
|
|
|
*/ |
39
|
|
|
abstract protected function isValidArray($values, Validator $validator, array $rules); |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
6 |
|
public function isValid($value, array $parameters) |
45
|
|
|
{ |
46
|
6 |
|
if (count($parameters) !== 2) { |
47
|
2 |
|
throw new ValidationException('Expecting two parameters.'); |
48
|
|
|
} |
49
|
6 |
|
if (!($parameters[0] instanceof Validator)) { |
50
|
2 |
|
throw new ValidationException('Expecting the first parameter to be an instance of a Validator.'); |
51
|
|
|
} |
52
|
6 |
|
return in_array($value, ['', null], true) || |
53
|
6 |
|
$this->isValidArray($value, $parameters[0], $parameters[1]); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|