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 mixed $item |
||
54 | * @param array $properties |
||
55 | * @return bool|string |
||
56 | * @throws InvalidArgumentException |
||
57 | */ |
||
58 | public function assertDocItem(string $itemKey, $item, array $properties) |
||
70 | |||
71 | /** |
||
72 | * @param string $itemKey |
||
73 | * @param array $properties |
||
74 | * @return bool |
||
75 | * @throws InvalidArgumentException |
||
76 | */ |
||
77 | private function checkType(string $itemKey, array $properties) |
||
87 | |||
88 | /** |
||
89 | * Validate given documents |
||
90 | * |
||
91 | * @param array $schema |
||
92 | * @param array $myDoc |
||
93 | * @param array $myKey |
||
94 | * @return array |
||
95 | * @throws InvalidArgumentException |
||
96 | */ |
||
97 | public function assertDoc(array $schema, array $myDoc, array $myKey = null) |
||
105 | |||
106 | /** |
||
107 | * @param array $schema |
||
108 | * @param array $myDoc |
||
109 | * @param string $key |
||
110 | * @param array $myKey |
||
111 | * @return array|bool|string |
||
112 | * @throws InvalidArgumentException; |
||
113 | */ |
||
114 | private function assertItem(array $schema, array $myDoc, string $key, array $myKey = null) |
||
132 | |||
133 | private function isMulti(array $schema, $myDoc, $key, array $vKey) |
||
145 | |||
146 | private function doesSchemaHasKey(array $schema, $key, $vKey) |
||
154 | |||
155 | // Is the value of the array[key] have same variable type |
||
156 | //that stated in the definition of the model array. |
||
157 | private function checkValueType($myDocKeyType, $schemaKey, $vKey) |
||
173 | } |
||
174 |