1 | <?php |
||
21 | class ValidatorForm implements ValidatorInterface |
||
22 | { |
||
23 | /** |
||
24 | * Stack of validators |
||
25 | * |
||
26 | * ['foo'] => ValidatorChain |
||
27 | * ['bar'] => ValidatorChain |
||
28 | * |
||
29 | * @var ValidatorChain[] |
||
30 | */ |
||
31 | protected $validators = []; |
||
32 | |||
33 | /** |
||
34 | * Exception with list of validation errors |
||
35 | * |
||
36 | * ['foo'] => "some field error" |
||
37 | * ['bar'] => "some field error" |
||
38 | * |
||
39 | * @var ValidatorException |
||
40 | */ |
||
41 | protected $exception; |
||
42 | |||
43 | /** |
||
44 | * Add chain to form |
||
45 | * |
||
46 | * @param string $name |
||
47 | * |
||
48 | * @return ValidatorChain |
||
49 | */ |
||
50 | 6 | public function add($name) : ValidatorChain |
|
55 | |||
56 | /** |
||
57 | * Get chain to form |
||
58 | * |
||
59 | * @param string $name |
||
60 | * |
||
61 | * @return ValidatorChain |
||
62 | */ |
||
63 | public function get($name) : ValidatorChain |
||
67 | |||
68 | /** |
||
69 | * Validate chain of rules |
||
70 | * |
||
71 | * @param array $input |
||
72 | * |
||
73 | * @return bool |
||
74 | */ |
||
75 | 6 | public function validate($input) : bool |
|
90 | |||
91 | /** |
||
92 | * Validate chain of rules for single item |
||
93 | * |
||
94 | * @param string $key |
||
95 | * @param mixed $value |
||
96 | * |
||
97 | * @return bool |
||
98 | */ |
||
99 | 6 | protected function validateItem($key, $value): bool |
|
110 | |||
111 | /** |
||
112 | * Assert |
||
113 | * |
||
114 | * @param mixed $input |
||
115 | * |
||
116 | * @return void |
||
117 | * @throws ValidatorException |
||
118 | */ |
||
119 | 6 | public function assert($input) |
|
125 | |||
126 | /** |
||
127 | * @inheritdoc |
||
128 | */ |
||
129 | public function __invoke($input) : bool |
||
133 | |||
134 | /** |
||
135 | * Get errors |
||
136 | * |
||
137 | * @return array |
||
138 | */ |
||
139 | 2 | public function getErrors() : array |
|
143 | |||
144 | /** |
||
145 | * Has errors? |
||
146 | * |
||
147 | * @return bool |
||
148 | */ |
||
149 | 6 | public function hasErrors() : bool |
|
153 | } |
||
154 |