1 | <?php |
||
5 | class Hint |
||
6 | { |
||
7 | const BOOL = 'bool'; |
||
8 | const INT = 'int'; |
||
9 | const FLOAT = 'float'; |
||
10 | const NUMERIC = 'numeric'; |
||
11 | const STRING = 'string'; |
||
12 | const ARR = 'array'; |
||
13 | |||
14 | /** |
||
15 | * @param string $varname |
||
16 | * @param mixed $value |
||
17 | * @param string|null $hint |
||
18 | * @param bool|null $nullable |
||
19 | * @throws \Exception |
||
20 | */ |
||
21 | public static function validateOrException($varname, $value, $hint = null, $nullable = null) |
||
28 | |||
29 | /** |
||
30 | * @param mixed $value |
||
31 | * @param string|null $hint |
||
32 | * @param bool|null $nullable |
||
33 | * @return bool |
||
34 | */ |
||
35 | public static function validate($value, $hint = null, $nullable = null) |
||
50 | |||
51 | /** |
||
52 | * @param string $hint |
||
53 | * @return bool |
||
54 | */ |
||
55 | protected static function isIteratableHint($hint) |
||
59 | |||
60 | /** |
||
61 | * @param string $hint |
||
62 | * @return string |
||
63 | */ |
||
64 | protected static function getHint($hint) |
||
72 | |||
73 | /** |
||
74 | * @param mixed $value |
||
75 | * @return bool |
||
76 | */ |
||
77 | protected static function isIteratableValue($value) |
||
81 | |||
82 | /** |
||
83 | * @param mixed $value |
||
84 | * @param string $hint |
||
85 | * @param bool|null $nullable |
||
86 | * @return bool |
||
87 | */ |
||
88 | protected static function validateOne($value, $hint, $nullable) |
||
98 | |||
99 | /** |
||
100 | * @param mixed $value |
||
101 | * @param string $hint |
||
102 | * @param bool|null $nullable |
||
103 | * @return bool |
||
104 | */ |
||
105 | protected static function validateMany($value, $hint, $nullable) |
||
115 | |||
116 | /** |
||
117 | * @param mixed $value |
||
118 | * @param bool|null $nullable |
||
119 | * @return bool |
||
120 | */ |
||
121 | public static function validateBool($value, $nullable = null) |
||
129 | |||
130 | /** |
||
131 | * @param mixed $value |
||
132 | * @param bool|null $nullable |
||
133 | * @return bool |
||
134 | */ |
||
135 | public static function validateInt($value, $nullable = null) |
||
143 | |||
144 | /** |
||
145 | * @param mixed $value |
||
146 | * @param bool|null $nullable |
||
147 | * @return bool |
||
148 | */ |
||
149 | public static function validateFloat($value, $nullable = null) |
||
157 | |||
158 | /** |
||
159 | * @param mixed $value |
||
160 | * @param bool|null $nullable |
||
161 | * @return bool |
||
162 | */ |
||
163 | public static function validateNumeric($value, $nullable = null) |
||
171 | |||
172 | /** |
||
173 | * @param mixed $value |
||
174 | * @param bool|null $nullable |
||
175 | * @return bool |
||
176 | */ |
||
177 | public static function validateString($value, $nullable = null) |
||
185 | |||
186 | /** |
||
187 | * @param mixed $value |
||
188 | * @param bool|null $nullable |
||
189 | * @return bool |
||
190 | */ |
||
191 | public static function validateArray($value, $nullable = null) |
||
199 | |||
200 | /** |
||
201 | * @param mixed $value |
||
202 | * @param string $hint |
||
203 | * @param bool|null $nullable |
||
204 | * @return bool |
||
205 | */ |
||
206 | public static function validateObject($value, $hint, $nullable = null) |
||
216 | |||
217 | /** |
||
218 | * @param bool|null $nullable |
||
219 | * @return bool |
||
220 | */ |
||
221 | protected static function isNullableScalar($nullable = null) |
||
225 | |||
226 | /** |
||
227 | * @param bool|null $nullable |
||
228 | * @return bool |
||
229 | */ |
||
230 | protected static function isNullableArrayOrObject($nullable = null) |
||
234 | |||
235 | /** |
||
236 | * @param callable $method |
||
237 | * @param string $value |
||
238 | * @param bool|null $nullable |
||
239 | * @return bool |
||
240 | */ |
||
241 | protected static function validateByCallable($method, $value, $nullable) |
||
249 | } |
||
250 |