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 | ]; |
||
26 | |||
27 | /** |
||
28 | * The translator to use fro the exception message. |
||
29 | * |
||
30 | * @var callable |
||
31 | */ |
||
32 | protected $translator = null; |
||
33 | |||
34 | /** |
||
35 | * Errors from the validation. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $errors = []; |
||
40 | |||
41 | /** |
||
42 | * The 'errors' attribute name. |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $errors_name = 'errors'; |
||
47 | |||
48 | /** |
||
49 | * The 'has_error' attribute name. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $has_errors_name = 'has_errors'; |
||
54 | |||
55 | /** |
||
56 | * The 'validators' attribute name. |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $validators_name = 'validators'; |
||
61 | |||
62 | /** |
||
63 | * The 'translator' attribute name. |
||
64 | * |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $translator_name = 'translator'; |
||
68 | |||
69 | /** |
||
70 | * Create new Validator service provider. |
||
71 | * |
||
72 | * @param null|array|ArrayAccess $validators |
||
73 | * @param null|callable $translator |
||
74 | * @param []|array $options |
||
|
|||
75 | */ |
||
76 | 25 | public function __construct($validators = null, $translator = null, $options = []) |
|
87 | |||
88 | /** |
||
89 | * Validation middleware invokable class. |
||
90 | * |
||
91 | * @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request |
||
92 | * @param \Psr\Http\Message\ResponseInterface $response PSR7 response |
||
93 | * @param callable $next Next middleware |
||
94 | * |
||
95 | * @return \Psr\Http\Message\ResponseInterface |
||
96 | */ |
||
97 | 25 | public function __invoke($request, $response, $next) |
|
111 | |||
112 | /** |
||
113 | * Validate the parameters by the given params, validators and actual keys. |
||
114 | * This method populates the $errors attribute. |
||
115 | * |
||
116 | * @param array $params The array of parameters. |
||
117 | * @param array $validators The array of validators. |
||
118 | * @param array $actualKeys An array that will save all the keys of the tree to retrieve the correct value. |
||
119 | */ |
||
120 | 25 | private function validate($params = [], $validators = [], $actualKeys = []) |
|
143 | |||
144 | /** |
||
145 | * Get the nested parameter value. |
||
146 | * |
||
147 | * @param array $params An array that represents the values of the parameters. |
||
148 | * @param array $keys An array that represents the tree of keys to use. |
||
149 | * |
||
150 | * @return mixed The nested parameter value by the given params and tree of keys. |
||
151 | */ |
||
152 | 24 | private function getNestedParam($params = [], $keys = []) |
|
168 | |||
169 | /** |
||
170 | * Check if the given $params is an array like variable. |
||
171 | * |
||
172 | * @param array $params The variable to check. |
||
173 | * |
||
174 | * @return boolean Returns true if the given $params parameter is array like. |
||
175 | */ |
||
176 | 24 | private function isArrayLike($params) |
|
180 | |||
181 | /** |
||
182 | * Check if there are any errors. |
||
183 | * |
||
184 | * @return bool |
||
185 | */ |
||
186 | 25 | public function hasErrors() |
|
190 | |||
191 | /** |
||
192 | * Get errors. |
||
193 | * |
||
194 | * @return array The errors array. |
||
195 | */ |
||
196 | 25 | public function getErrors() |
|
200 | |||
201 | /** |
||
202 | * Get validators. |
||
203 | * |
||
204 | * @return array The validators array. |
||
205 | */ |
||
206 | 25 | public function getValidators() |
|
210 | |||
211 | /** |
||
212 | * Set validators. |
||
213 | * |
||
214 | * @param array $validators The validators array. |
||
215 | */ |
||
216 | 1 | public function setValidators($validators) |
|
220 | |||
221 | /** |
||
222 | * Get translator. |
||
223 | * |
||
224 | * @return callable The translator. |
||
225 | */ |
||
226 | 25 | public function getTranslator() |
|
230 | |||
231 | /** |
||
232 | * Set translator. |
||
233 | * |
||
234 | * @param callable $translator The translator. |
||
235 | */ |
||
236 | 1 | public function setTranslator($translator) |
|
240 | } |
||
241 |
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.