1 | <?php |
||
9 | class Validator |
||
10 | { |
||
11 | static protected $constraints = [ |
||
12 | 'Boolean' => DataType\Boolean::class, |
||
13 | 'Date' => DataType\Date::class, |
||
14 | 'Double' => DataType\Double::class, |
||
15 | 'Email' => DataType\Email::class, |
||
16 | 'Enum' => DataType\Enum::class, |
||
17 | 'FilePath' => DataType\FilePath::class, |
||
18 | 'Html' => DataType\Html::class, |
||
19 | 'Integer' => DataType\Integer::class, |
||
20 | 'Ipv4' => DataType\Ipv4::class, |
||
21 | 'Ipv6' => DataType\Ipv6::class, |
||
22 | 'MacAddress' => DataType\MacAddress::class, |
||
23 | 'PhoneNumber' => DataType\PhoneNumber::class, |
||
24 | 'Regex' => DataType\Regex::class, |
||
25 | 'Slug' => DataType\Slug::class, |
||
26 | 'Text' => DataType\Text::class, |
||
27 | 'Url' => DataType\Url::class, |
||
28 | 'Uuid' => DataType\Uuid::class |
||
29 | ]; |
||
30 | |||
31 | static protected $validTypes = [ |
||
32 | 'Boolean' => 'boolean', |
||
33 | 'Date' => 'string', |
||
34 | 'Double' => 'float', |
||
35 | 'Email' => 'string', |
||
36 | 'Enum' => 'string', |
||
37 | 'FilePath' => 'string', |
||
38 | 'Html' => 'string', |
||
39 | 'Integer' => 'integer', |
||
40 | 'Ipv4' => 'string', |
||
41 | 'Ipv6' => 'string', |
||
42 | 'MacAddress' => 'string', |
||
43 | 'PhoneNumber' => 'string', |
||
44 | 'Regex' => 'string', |
||
45 | 'Slug' => 'string', |
||
46 | 'Text' => 'string', |
||
47 | 'Url' => 'string', |
||
48 | 'Uuid' => 'string' |
||
49 | ]; |
||
50 | |||
51 | /** |
||
52 | * @param string $itemKey |
||
53 | * @param array $properties |
||
54 | * @return bool |
||
55 | * @throws InvalidArgumentException |
||
56 | */ |
||
57 | private function checkType(string $itemKey, array $properties) |
||
67 | |||
68 | /** |
||
69 | * @param string $itemKey |
||
70 | * @param mixed $item |
||
71 | * @param array $properties |
||
72 | * @return bool|string |
||
73 | * @throws InvalidArgumentException |
||
74 | */ |
||
75 | public function assertDocItem(string $itemKey, $item, array $properties) |
||
87 | |||
88 | /** |
||
89 | * Validate given documents |
||
90 | * |
||
91 | * @param array $schema |
||
92 | * @param array $myDoc |
||
93 | * @param string $myKey |
||
94 | * @return array |
||
95 | * @throws InvalidArgumentException |
||
96 | */ |
||
97 | public function assertDoc(array $schema, array $myDoc, string $myKey = null) |
||
136 | } |
||
137 |