1 | <?php |
||
14 | class Validation |
||
15 | { |
||
16 | /** |
||
17 | * Validators. |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $validators = []; |
||
22 | |||
23 | /** |
||
24 | * Options. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $options = [ |
||
29 | 'useTemplate' => false, |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * The translator to use for the exception message. |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $translator = null; |
||
38 | |||
39 | /** |
||
40 | * Errors from the validation. |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $errors = []; |
||
45 | |||
46 | /** |
||
47 | * The 'errors' attribute name. |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $errors_name = 'errors'; |
||
52 | |||
53 | /** |
||
54 | * The 'has_error' attribute name. |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $has_errors_name = 'has_errors'; |
||
59 | |||
60 | /** |
||
61 | * The 'validators' attribute name. |
||
62 | * |
||
63 | * @var string |
||
64 | */ |
||
65 | protected $validators_name = 'validators'; |
||
66 | |||
67 | /** |
||
68 | * The 'translator' attribute name. |
||
69 | * |
||
70 | * @var string |
||
71 | */ |
||
72 | protected $translator_name = 'translator'; |
||
73 | |||
74 | /** |
||
75 | * Create new Validator service provider. |
||
76 | 25 | * |
|
77 | * @param null|array|ArrayAccess $validators |
||
78 | * @param null|array $translator |
||
79 | 25 | * @param []|array $options |
|
|
|||
80 | 24 | */ |
|
81 | 25 | public function __construct($validators = null, $translator = null, $options = []) |
|
92 | |||
93 | /** |
||
94 | * Validation middleware invokable class. |
||
95 | * |
||
96 | * @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request |
||
97 | 25 | * @param \Psr\Http\Server\RequestHandlerInterface $response PSR7 response |
|
98 | * |
||
99 | 25 | * @return \Psr\Http\Message\ResponseInterface |
|
100 | 25 | */ |
|
101 | 25 | public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
123 | 25 | ||
124 | 24 | /** |
|
125 | 24 | * Validate the parameters by the given params, validators and actual keys. |
|
126 | 24 | * This method populates the $errors attribute. |
|
127 | 9 | * |
|
128 | 9 | * @param array $params The array of parameters. |
|
129 | * @param array $validators The array of validators. |
||
130 | 24 | * @param array $actualKeys An array that will save all the keys of the tree to retrieve the correct value. |
|
131 | 24 | */ |
|
132 | 14 | private function validate($params = [], $validators = [], $actualKeys = []) |
|
159 | 22 | ||
160 | 22 | /** |
|
161 | * Get the nested parameter value. |
||
162 | 22 | * |
|
163 | 14 | * @param array $params An array that represents the values of the parameters. |
|
164 | 3 | * @param array $keys An array that represents the tree of keys to use. |
|
165 | * |
||
166 | * @return mixed The nested parameter value by the given params and tree of keys. |
||
167 | */ |
||
168 | private function getNestedParam($params = [], $keys = []) |
||
184 | |||
185 | /** |
||
186 | 25 | * Check if the given $params is an array like variable. |
|
187 | * |
||
188 | 25 | * @param array $params The variable to check. |
|
189 | * |
||
190 | * @return bool Returns true if the given $params parameter is array like. |
||
191 | */ |
||
192 | private function isArrayLike($params) |
||
196 | 25 | ||
197 | /** |
||
198 | 25 | * Check if there are any errors. |
|
199 | * |
||
200 | * @return bool |
||
201 | */ |
||
202 | public function hasErrors() |
||
206 | 25 | ||
207 | /** |
||
208 | 25 | * Get errors. |
|
209 | * |
||
210 | * @return array The errors array. |
||
211 | */ |
||
212 | public function getErrors() |
||
216 | 1 | ||
217 | /** |
||
218 | 1 | * Get validators. |
|
219 | 1 | * |
|
220 | * @return array The validators array. |
||
221 | */ |
||
222 | public function getValidators() |
||
226 | 25 | ||
227 | /** |
||
228 | 25 | * Set validators. |
|
229 | * |
||
230 | * @param array $validators The validators array. |
||
231 | */ |
||
232 | public function setValidators($validators) |
||
236 | 1 | ||
237 | /** |
||
238 | 1 | * Get translator. |
|
239 | 1 | * |
|
240 | * @return callable The translator. |
||
241 | */ |
||
242 | public function getTranslator() |
||
246 | |||
247 | /** |
||
248 | * Set translator. |
||
249 | * |
||
250 | * @param callable $translator The translator. |
||
251 | */ |
||
252 | public function setTranslator($translator) |
||
256 | } |
||
257 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.