1 | <?php |
||
10 | class Validation |
||
11 | { |
||
12 | /** |
||
13 | * Validators. |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $validators = []; |
||
18 | |||
19 | /** |
||
20 | * Options. |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $options = [ |
||
25 | 'useTemplate' => false, |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * The translator to use fro the exception message. |
||
30 | * |
||
31 | * @var callable |
||
32 | */ |
||
33 | protected $translator = null; |
||
34 | |||
35 | /** |
||
36 | * Errors from the validation. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $errors = []; |
||
41 | |||
42 | /** |
||
43 | * The 'errors' attribute name. |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $errors_name = 'errors'; |
||
48 | |||
49 | /** |
||
50 | * The 'has_error' attribute name. |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $has_errors_name = 'has_errors'; |
||
55 | |||
56 | /** |
||
57 | * The 'validators' attribute name. |
||
58 | * |
||
59 | * @var string |
||
60 | */ |
||
61 | protected $validators_name = 'validators'; |
||
62 | |||
63 | /** |
||
64 | * The 'translator' attribute name. |
||
65 | * |
||
66 | * @var string |
||
67 | */ |
||
68 | protected $translator_name = 'translator'; |
||
69 | |||
70 | /** |
||
71 | * Create new Validator service provider. |
||
72 | * |
||
73 | * @param null|array|ArrayAccess $validators |
||
74 | * @param null|callable $translator |
||
75 | * @param []|array $options |
||
|
|||
76 | */ |
||
77 | 25 | public function __construct($validators = null, $translator = null, $options = []) |
|
88 | |||
89 | /** |
||
90 | * Validation middleware invokable class. |
||
91 | * |
||
92 | * @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request |
||
93 | * @param \Psr\Http\Message\ResponseInterface $response PSR7 response |
||
94 | * @param callable $next Next middleware |
||
95 | * |
||
96 | * @return \Psr\Http\Message\ResponseInterface |
||
97 | */ |
||
98 | 25 | public function __invoke($request, $response, $next) |
|
112 | |||
113 | /** |
||
114 | * Validate the parameters by the given params, validators and actual keys. |
||
115 | * This method populates the $errors attribute. |
||
116 | * |
||
117 | * @param array $params The array of parameters. |
||
118 | * @param array $validators The array of validators. |
||
119 | * @param array $actualKeys An array that will save all the keys of the tree to retrieve the correct value. |
||
120 | */ |
||
121 | 25 | private function validate($params = [], $validators = [], $actualKeys = []) |
|
148 | |||
149 | /** |
||
150 | * Get the nested parameter value. |
||
151 | * |
||
152 | * @param array $params An array that represents the values of the parameters. |
||
153 | * @param array $keys An array that represents the tree of keys to use. |
||
154 | * |
||
155 | * @return mixed The nested parameter value by the given params and tree of keys. |
||
156 | */ |
||
157 | 24 | private function getNestedParam($params = [], $keys = []) |
|
173 | |||
174 | /** |
||
175 | * Retrieve the route info as an array if any. |
||
176 | * |
||
177 | * @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request |
||
178 | * |
||
179 | * @return array An array with the array info. |
||
180 | */ |
||
181 | 25 | private function retrieveRouteInfo($request){ |
|
188 | |||
189 | /** |
||
190 | * Check if there are any errors. |
||
191 | * |
||
192 | * @return bool |
||
193 | */ |
||
194 | 25 | public function hasErrors() |
|
198 | |||
199 | /** |
||
200 | * Get errors. |
||
201 | * |
||
202 | * @return array The errors array. |
||
203 | */ |
||
204 | 25 | public function getErrors() |
|
208 | |||
209 | /** |
||
210 | * Get validators. |
||
211 | * |
||
212 | * @return array The validators array. |
||
213 | */ |
||
214 | 25 | public function getValidators() |
|
218 | |||
219 | /** |
||
220 | * Set validators. |
||
221 | * |
||
222 | * @param array $validators The validators array. |
||
223 | */ |
||
224 | 1 | public function setValidators($validators) |
|
228 | |||
229 | /** |
||
230 | * Get translator. |
||
231 | * |
||
232 | * @return callable The translator. |
||
233 | */ |
||
234 | 25 | public function getTranslator() |
|
238 | |||
239 | /** |
||
240 | * Set translator. |
||
241 | * |
||
242 | * @param callable $translator The translator. |
||
243 | */ |
||
244 | 1 | public function setTranslator($translator) |
|
248 | } |
||
249 |
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.