1 | <?php |
||
16 | class Type { |
||
17 | |||
18 | /** |
||
19 | * Type to validate against. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | private $type; |
||
24 | |||
25 | /** |
||
26 | * Type constructor. |
||
27 | * |
||
28 | * @param string $type |
||
29 | * @param bool $key_type |
||
30 | */ |
||
31 | 417 | public function __construct( $type, $key_type = false ) { |
|
34 | |||
35 | /** |
||
36 | * Get validation type. |
||
37 | * |
||
38 | * @return string |
||
39 | */ |
||
40 | 189 | public function get_type() { |
|
43 | |||
44 | /** |
||
45 | * Returns whether the type is an Axolotl model. |
||
46 | * |
||
47 | * @return bool |
||
48 | */ |
||
49 | 309 | public function is_model() { |
|
57 | |||
58 | /** |
||
59 | * Create a new model from the given data. |
||
60 | * |
||
61 | * @param array $data Data for the model. |
||
62 | * |
||
63 | * @return Model |
||
64 | */ |
||
65 | 9 | public function create_model( array $data ) { |
|
68 | |||
69 | /** |
||
70 | * Validates an array of element. |
||
71 | * |
||
72 | * @param array $elements Elements to be validated. |
||
73 | * |
||
74 | * @throws InvalidArgumentException |
||
75 | */ |
||
76 | 222 | public function validate_elements( array $elements ) { |
|
81 | |||
82 | /** |
||
83 | * Validate whether the |
||
84 | * |
||
85 | * @param mixed $element Element to validate. |
||
86 | * |
||
87 | * @throws InvalidArgumentException |
||
88 | */ |
||
89 | 351 | public function validate_element( $element ) { |
|
110 | |||
111 | /** |
||
112 | * Determine the type to validate against. |
||
113 | * |
||
114 | * @param string $type Type to determine. |
||
115 | * @param bool $key_type Whether the type is for keys. |
||
116 | * |
||
117 | * @return string |
||
118 | * |
||
119 | * @throws InvalidArgumentException |
||
120 | */ |
||
121 | 417 | private function determine( $type, $key_type = false ) { |
|
136 | |||
137 | /** |
||
138 | * Determines whether the given type exists. |
||
139 | * |
||
140 | * @param string $type Type to check. |
||
141 | * |
||
142 | * @return bool |
||
143 | */ |
||
144 | 396 | private function non_scalar_type_exists( $type ) { |
|
149 | |||
150 | /** |
||
151 | * Returns the type if it's scalar, otherwise, returns null. |
||
152 | * |
||
153 | * @param string $type Type to check. |
||
154 | * |
||
155 | * @return string|null |
||
156 | */ |
||
157 | 372 | private function determine_scalar( $type ) { |
|
172 | } |
||
173 |