1 | <?php |
||
19 | class TypeHandler |
||
20 | { |
||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $types; |
||
25 | |||
26 | /** |
||
27 | * @var InstantiatorInterface |
||
28 | */ |
||
29 | protected $defaultInstantiator; |
||
30 | |||
31 | public function __construct() |
||
32 | { |
||
33 | $this->types = [ |
||
34 | 'bool' => BoolNode::class, |
||
35 | 'int' => IntNode::class, |
||
36 | 'float' => FloatNode::class, |
||
37 | 'double' => FloatNode::class, |
||
38 | 'numeric' => NumericNode::class, |
||
39 | 'string' => StringNode::class, |
||
40 | 'array' => BaseNode::class, |
||
41 | 'object' => ObjectNode::class, |
||
42 | 'datetime' => DateTimeNode::class, |
||
43 | ]; |
||
44 | |||
45 | $this->defaultInstantiator = new SetInstantiator(); |
||
46 | } |
||
47 | |||
48 | public function addType(string $name, string $class) |
||
52 | |||
53 | public function getType(string $name): BaseNode |
||
90 | |||
91 | protected function isClassType(string $type): bool |
||
92 | { |
||
93 | return (class_exists($type) || interface_exists($type)) && $type != 'datetime'; |
||
94 | } |
||
95 | |||
96 | protected function isCollectionType(string $type): bool |
||
106 | |||
107 | protected function isScalarCollectionType(string $type): bool |
||
117 | |||
118 | protected function getCollectionType(string $type): string |
||
128 | } |
||
129 |