-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
65 lines (62 loc) · 1.38 KB
/
test.php
File metadata and controls
65 lines (62 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
require_once __DIR__ . '/index.php';
use function Zec\Utils\z;
$parser = z()->options([
'name' => z()->string(),
'age' => z()->number()->min([
'min' => 18,
'mege' => 'Value must be at least 18'
]),
'email' => z()->email(),
'hobbies' => z()->each(z()->string()->min([
'min' => 3,
'message' => 'Value must be at least 3 characters long'
]))
]);
$validErrorResponse = [
[
'parser' => 'min',
'min' => 18,
'value' => 1,
'message' => 'Value must be at least 18',
'path' => [
'age'
]
],
[
'parser' => 'email',
'value' => 'jane.doe@examplecom',
'message' => 'Invalid email address',
'path' => [
'email'
]
],
[
'parser' => 'string',
'value' => 5,
'message' => 'Invalid string value',
'path' => [
'hobbies',
'3'
]
],
[
'parser' => 'string',
'value' => 6,
'message' => 'Invalid string value',
'path' => [
'hobbies',
'4'
]
]
];
try {
$response = $parser->parseOrThrow([
'name' => 'Jane Doe',
'age' => 1,
'email' => 'jane.doe@examplecom',
'hobbies' => ['photography', 'traveling', 'reading', 5, 6]
]);
} catch (\Zec\ZecError $e) {
$e->log();
}