1 | <?php declare(strict_types=1); |
||
5 | class TypeChecker |
||
6 | { |
||
7 | private $value; |
||
8 | |||
9 | const DOCBLOCK_PARAM_PATTERN = "/^(([a-z\\\])+(\[\])?\|?)+$/i"; |
||
10 | |||
11 | const TYPES = [ |
||
12 | 'string', |
||
13 | 'integer', |
||
14 | 'int', |
||
15 | 'float', |
||
16 | 'boolean', |
||
17 | 'bool', |
||
18 | 'array', |
||
19 | 'object', |
||
20 | 'null', |
||
21 | 'resource', |
||
22 | ]; |
||
23 | |||
24 | private $remap = [ |
||
25 | 'int' => 'integer', |
||
26 | 'bool' => 'boolean', |
||
27 | ]; |
||
28 | |||
29 | /** |
||
30 | * Grabs the value to check |
||
31 | */ |
||
32 | public function __construct($value) |
||
36 | |||
37 | /** |
||
38 | * Check the already supplied value against the type specified |
||
39 | */ |
||
40 | public function check(string $type): bool |
||
61 | |||
62 | public function checkAsClosure(\Closure $closure): bool |
||
70 | |||
71 | private function isArrayOf(string $type, $value): bool |
||
84 | |||
85 | private function checkType(string $type, $value): bool |
||
98 | |||
99 | /** |
||
100 | * Clean up the supplied array of types |
||
101 | * |
||
102 | * @param array $types |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | private function normaliseTypes(array $types): array |
||
110 | |||
111 | /** |
||
112 | * Determine if the supplied type is one of php's base values |
||
113 | * |
||
114 | * @param string $type |
||
115 | * @return bool |
||
116 | */ |
||
117 | private function isBaseType(string $type): bool |
||
121 | } |
||
122 |