@@ -43,12 +43,20 @@ public function __construct(
43
43
$ this ->nullable = $ this ->nullable ? $ this ->nullable : null ;
44
44
}
45
45
46
- public static function fromDataPropery ( DataProperty $ property ): self
46
+ public static function fromReflectopnProperty ( ReflectionProperty $ reflection ): self
47
47
{
48
+ $ property = DataProperty::create ($ reflection );
49
+
48
50
$ type = $ property ->type ;
49
51
50
- if ($ type ->dataClass ) {
51
- return self ::fromData ($ type ->dataClass , $ type ->isNullable || $ type ->isOptional );
52
+ /** @var null|string */
53
+ $ data_class = $ type ->dataClass ;
54
+
55
+ if ($ type ->isDataObject && $ data_class ) {
56
+ return self ::fromData ($ data_class , $ type ->isNullable || $ type ->isOptional );
57
+ }
58
+ if ($ type ->isDataCollectable && $ data_class ) {
59
+ return self ::fromDataCollection ($ data_class , $ type ->isNullable || $ type ->isOptional );
52
60
}
53
61
54
62
/** @var null|string */
@@ -58,7 +66,7 @@ public static function fromDataPropery(DataProperty $property): self
58
66
throw new \RuntimeException ("Parameter {$ property ->name } has no type defined " );
59
67
}
60
68
61
- return self ::fromDataReflection (type_name: $ other_type , nullable: $ type ->isNullable );
69
+ return self ::fromDataReflection (type_name: $ other_type , reflection: $ reflection , nullable: $ type ->isNullable );
62
70
}
63
71
64
72
public static function fromDataReflection (
@@ -187,6 +195,21 @@ protected static function fromData(string $type_name, bool $nullable): self
187
195
);
188
196
}
189
197
198
+ protected static function fromDataCollection (string $ type_name , bool $ nullable ): self
199
+ {
200
+ $ type_name = ltrim ($ type_name , '\\' );
201
+
202
+ if (! is_a ($ type_name , LaravelData::class, true )) {
203
+ throw new \RuntimeException ("Type {$ type_name } is not a Data class " );
204
+ }
205
+
206
+ return new self (
207
+ type: 'array ' ,
208
+ items: self ::fromData ($ type_name , false ),
209
+ nullable: $ nullable ,
210
+ );
211
+ }
212
+
190
213
protected static function fromListDocblock (ReflectionMethod |ReflectionFunction |ReflectionProperty $ reflection , bool $ nullable ): self
191
214
{
192
215
$ docs = $ reflection ->getDocComment ();
0 commit comments