|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +declare(strict_types=1); |
| 4 | +/** |
| 5 | + * 本文件属于KK馆版权所有。 |
| 6 | + * This file belong to KKGUAN. |
| 7 | + */ |
3 | 8 | require __DIR__ . '/../vendor/autoload.php'; |
4 | 9 |
|
5 | 10 | use KK\Validation\ValidationErrorDumper; |
|
38 | 43 |
|
39 | 44 | $validator = new Validator([ |
40 | 45 | 'type' => 'required|numeric', |
41 | | - 'foo.*.bar' => 'numeric|max:256' |
| 46 | + 'foo.*.bar' => 'numeric|max:256', |
42 | 47 | ]); |
43 | 48 | try { |
44 | 49 | $validator->validate([ |
45 | | - 'type' => 'xxx' |
| 50 | + 'type' => 'xxx', |
46 | 51 | ]); |
47 | 52 | } catch (ValidationException $e) { |
48 | 53 | // Attribute 'type' violates the following rules: numeric |
|
51 | 56 | try { |
52 | 57 | $validator->validate([ |
53 | 58 | 'type' => 1, |
54 | | - 'foo' => [['bar' => '1024']] |
| 59 | + 'foo' => [['bar' => '1024']], |
55 | 60 | ]); |
56 | 61 | } catch (ValidationException $e) { |
57 | 62 | // Attribute 'foo.0.bar' violates the following rules: max:256 |
58 | 63 | echo ValidationErrorDumper::dump($e->errors()) . "\n"; |
59 | 64 | } |
60 | 65 |
|
61 | 66 | $validator = new Validator([ |
62 | | - 'a.*.b.*.c.*.d.*.e' => 'numeric' |
| 67 | + 'a.*.b.*.c.*.d.*.e' => 'numeric', |
63 | 68 | ]); |
64 | 69 | try { |
65 | 70 | $validator->validate([ |
66 | | - 'a' => [['b' => [['c' => [['d' => [['e' => 'xxx']]]]]]]] |
| 71 | + 'a' => [['b' => [['c' => [['d' => [['e' => 'xxx']]]]]]]], |
67 | 72 | ]); |
68 | 73 | } catch (ValidationException $e) { |
69 | 74 | // Attribute 'a.0.b.0.c.0.d.0.e' violates the following rules: numeric |
70 | 75 | echo ValidationErrorDumper::dump($e->errors()) . "\n"; |
71 | 76 | } |
72 | 77 |
|
73 | 78 | $validator = new Validator([ |
74 | | - '*' => 'numeric' |
| 79 | + '*' => 'numeric', |
75 | 80 | ]); |
76 | 81 | try { |
77 | 82 | $validator->validate(['0', '1', '2', '3']); |
|
88 | 93 | } |
89 | 94 |
|
90 | 95 | $validator = new Validator([ |
91 | | - 'foo.*' => 'integer' |
| 96 | + 'foo.*' => 'integer', |
92 | 97 | ]); |
93 | 98 | try { |
94 | 99 | $validator->validate(['foo' => ['0', '0.1', '0.2', '1']]); |
|
105 | 110 | } |
106 | 111 |
|
107 | 112 | $validator = new Validator([ |
108 | | - '*.*.*' => 'integer' |
| 113 | + '*.*.*' => 'integer', |
109 | 114 | ]); |
110 | 115 | try { |
111 | 116 | $validator->validate(['foo' => ['bar' => 'not array']]); |
|
126 | 131 | } |
127 | 132 |
|
128 | 133 | $validator = new Validator([ |
129 | | - 'foo' => 'string|max:255' |
| 134 | + 'foo' => 'string|max:255', |
130 | 135 | ]); |
131 | 136 | try { |
132 | 137 | $validator->validate(['foo' => []]); |
|
142 | 147 | } |
143 | 148 |
|
144 | 149 | $validator = new Validator([ |
145 | | - 'foo' => 'required|max:255' |
| 150 | + 'foo' => 'required|max:255', |
146 | 151 | ]); |
147 | 152 | try { |
148 | 153 | $validator->validate(['foo' => null]); |
|
158 | 163 | } |
159 | 164 |
|
160 | 165 | $validator = new Validator([ |
161 | | - 'foo' => 'max:255' |
| 166 | + 'foo' => 'max:255', |
162 | 167 | ]); |
163 | 168 | try { |
164 | 169 | $validator->validate(['foo' => null]); |
|
167 | 172 | } |
168 | 173 |
|
169 | 174 | $validator = new Validator([ |
170 | | - 'foo' => 'min:1|max:255' |
| 175 | + 'foo' => 'min:1|max:255', |
171 | 176 | ]); |
172 | 177 | try { |
173 | 178 | $validator->validate(['foo' => null]); |
|
189 | 194 | } |
190 | 195 |
|
191 | 196 | $validator = new Validator([ |
192 | | - 'foo' => 'in:1, 2, 3' |
| 197 | + 'foo' => 'in:1, 2, 3', |
193 | 198 | ]); |
194 | 199 | try { |
195 | 200 | $validator->validate(['foo' => null]); |
|
226 | 231 | } |
227 | 232 |
|
228 | 233 | $validator = new Validator([ |
229 | | - 'foo' => 'required|array|in:9, 8, 7, 6, 5, 4, 3' // in map |
| 234 | + 'foo' => 'required|array|in:9, 8, 7, 6, 5, 4, 3', // in map |
230 | 235 | ]); |
231 | 236 | try { |
232 | 237 | $validator->validate(['foo' => []]); |
|
242 | 247 | } |
243 | 248 |
|
244 | 249 | $validator = new Validator([ |
245 | | - 'foo' => 'alpha' |
| 250 | + 'foo' => 'alpha', |
246 | 251 | ]); |
247 | 252 | try { |
248 | 253 | $validator->validate(['foo' => '1']); |
|
257 | 262 | } |
258 | 263 |
|
259 | 264 | $validator = new Validator([ |
260 | | - 'foo' => 'alpha_num' |
| 265 | + 'foo' => 'alpha_num', |
261 | 266 | ]); |
262 | 267 | try { |
263 | 268 | $validator->validate(['foo' => 'xyz123']); |
|
272 | 277 | } |
273 | 278 |
|
274 | 279 | $validator = new Validator([ |
275 | | - 'foo' => 'alpha_dash' |
| 280 | + 'foo' => 'alpha_dash', |
276 | 281 | ]); |
277 | 282 | try { |
278 | 283 | $validator->validate(['foo' => 'xyz_123-v4']); |
|
0 commit comments