1 | <?php |
||
29 | class Builder |
||
30 | { |
||
31 | /** @var Reader */ |
||
32 | private $reader; |
||
33 | /** @var PropertyFilter */ |
||
34 | private $propertyFilter; |
||
35 | /** @var PropertyMapper */ |
||
36 | private $propertyMapper; |
||
37 | |||
38 | /** @var TypeRegistry */ |
||
39 | private $typeRegistry; |
||
40 | /** @var array|Type[] Built in type, key being the type name, value a blueprint instance */ |
||
41 | private $builtInTypes; |
||
42 | |||
43 | /** |
||
44 | * @return Builder |
||
45 | */ |
||
46 | 43 | public static function createDefault() |
|
67 | |||
68 | /** |
||
69 | * C'tor |
||
70 | * |
||
71 | * @param Reader $reader |
||
72 | * @param PropertyFilter $propertyFilter |
||
73 | * @param PropertyMapper $propertyMapper |
||
74 | */ |
||
75 | 44 | public function __construct(Reader $reader, PropertyFilter $propertyFilter, PropertyMapper $propertyMapper) |
|
94 | |||
95 | /** |
||
96 | * @return PropertyFilter |
||
97 | */ |
||
98 | 1 | public function getPropertyFilter() |
|
102 | |||
103 | /** |
||
104 | * @return PropertyMapper |
||
105 | */ |
||
106 | 1 | public function getPropertyMapper() |
|
110 | |||
111 | /** |
||
112 | * @return TypeRegistry |
||
113 | */ |
||
114 | 1 | public function getTypeRegistry() |
|
118 | |||
119 | /** |
||
120 | * @return Type[] |
||
121 | */ |
||
122 | 1 | public function getBuiltInTypes(): array |
|
126 | |||
127 | /** |
||
128 | * Build the full name for a type. |
||
129 | * |
||
130 | * For simple types this will return "String", "Int", etc. |
||
131 | * |
||
132 | * For generic type this will return e.g. Map<String,List<Int>> |
||
133 | * |
||
134 | * @param TypeRef $ref |
||
135 | * |
||
136 | * @return string |
||
137 | */ |
||
138 | 62 | public function buildFullName(TypeRef $ref): string |
|
154 | |||
155 | /** |
||
156 | * Build a type from a given TypeRef. |
||
157 | * |
||
158 | * This method is omnipotent, meaning that when ever we request a type that is already |
||
159 | * known, we will return the same instance of the Type. |
||
160 | * |
||
161 | * A type is considered to be known when the fullName |
||
162 | * a) matches a built in type like "String", "DateTime", "Int" |
||
163 | * b) is already present in the type registry |
||
164 | * |
||
165 | * @param TypeRef $ref |
||
166 | * |
||
167 | * @return Type |
||
168 | */ |
||
169 | 34 | public function buildForRef(TypeRef $ref) |
|
202 | |||
203 | /** |
||
204 | * Build the type from a given reflection class. |
||
205 | * |
||
206 | * @param \ReflectionClass $class |
||
207 | * |
||
208 | * @return Type |
||
209 | */ |
||
210 | 15 | public function buildForClass(\ReflectionClass $class) |
|
245 | |||
246 | /** |
||
247 | * @param ObjectType $type |
||
248 | * |
||
249 | * @return Property[] |
||
250 | */ |
||
251 | 1 | public function getAllProperties(ObjectType $type) |
|
267 | |||
268 | /** |
||
269 | * @param ObjectType $type |
||
270 | * @param \ReflectionClass $class |
||
271 | */ |
||
272 | 11 | private function populateObjectType(ObjectType $type, \ReflectionClass $class) |
|
309 | |||
310 | /** |
||
311 | * @param \ReflectionProperty $property |
||
312 | * |
||
313 | * @return Property |
||
314 | */ |
||
315 | 10 | private function buildProperty(\ReflectionProperty $property) |
|
326 | |||
327 | /** |
||
328 | * TODO: should we extract extended reflection functionality into the Mirror ? |
||
329 | * |
||
330 | * @param \ReflectionProperty $prop |
||
331 | * |
||
332 | * @return \ReflectionClass |
||
333 | */ |
||
334 | 10 | public static function getRealDeclaringClass(\ReflectionProperty $prop) |
|
338 | |||
339 | /** |
||
340 | * Get the exact class or trait that defines a property. |
||
341 | * |
||
342 | * TODO: should we extract extended reflection functionality into the Mirror ? |
||
343 | * |
||
344 | * @param \ReflectionClass $class |
||
345 | * @param \ReflectionProperty $prop |
||
346 | * |
||
347 | * @return \ReflectionClass |
||
348 | */ |
||
349 | 10 | private static function getRealDeclaringClassInternal(\ReflectionClass $class, \ReflectionProperty $prop) |
|
362 | |||
363 | /** |
||
364 | * Get the class declaring the property after traits are resolved. |
||
365 | * |
||
366 | * TODO: should we extract extended reflection functionality into the Mirror ? |
||
367 | * |
||
368 | * @param \ReflectionClass $class |
||
369 | * @param \ReflectionProperty $prop |
||
370 | * |
||
371 | * @return \ReflectionClass |
||
372 | */ |
||
373 | 10 | public static function getDeclaringClassInInheritanceChain(\ReflectionClass $class, \ReflectionProperty $prop) |
|
383 | } |
||
384 |