1 | <?php |
||
14 | final class ArrayAdapter implements ValidatorInterface |
||
15 | { |
||
16 | /** @var ValidatorInterface */ |
||
17 | private $validator; |
||
18 | |||
19 | /** @var bool */ |
||
20 | private $strictUniqueControl = true; |
||
21 | |||
22 | /** |
||
23 | * ArrayAdapter constructor. |
||
24 | * |
||
25 | * @param ValidatorInterface $validator |
||
26 | */ |
||
27 | 26 | public function __construct(ValidatorInterface $validator) |
|
31 | |||
32 | /** |
||
33 | * @param mixed $value |
||
34 | * |
||
35 | * @return bool |
||
36 | */ |
||
37 | 18 | public function validate($value): bool |
|
38 | { |
||
39 | 18 | if (!\is_array($value) || 0 === \count($value)) { |
|
40 | return false; |
||
41 | } |
||
42 | |||
43 | 18 | if ($this->isStrictUniqueControl() && \count($value) > \count(\array_unique($value))) { |
|
44 | 2 | return false; |
|
45 | } |
||
46 | |||
47 | 16 | foreach ($value as $item) { |
|
48 | 16 | if (!$this->validator->validate($item)) { |
|
49 | 16 | return false; |
|
50 | } |
||
51 | } |
||
52 | |||
53 | 16 | return true; |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * @return bool |
||
58 | */ |
||
59 | 18 | public function isStrictUniqueControl(): bool |
|
63 | |||
64 | /** |
||
65 | * @param bool $strictUniqueControl |
||
66 | */ |
||
67 | public function setStrictUniqueControl(bool $strictUniqueControl): void |
||
71 | } |
||
72 |