66
77use CuyZ \Valinor \Cache \Exception \InvalidSignatureToWarmup ;
88use CuyZ \Valinor \Definition \Repository \ClassDefinitionRepository ;
9+ use CuyZ \Valinor \Mapper \Object \Factory \ObjectBuilderFactory ;
10+ use CuyZ \Valinor \Mapper \Tree \Builder \ObjectImplementations ;
911use CuyZ \Valinor \Type \CompositeType ;
1012use CuyZ \Valinor \Type \Parser \Exception \InvalidType ;
1113use CuyZ \Valinor \Type \Parser \TypeParser ;
1214use CuyZ \Valinor \Type \Type ;
1315use CuyZ \Valinor \Type \Types \ClassType ;
16+ use CuyZ \Valinor \Type \Types \InterfaceType ;
1417
1518use function in_array ;
1619
@@ -19,15 +22,25 @@ final class RecursiveCacheWarmupService
1922{
2023 private TypeParser $ parser ;
2124
25+ private ObjectImplementations $ implementations ;
26+
2227 private ClassDefinitionRepository $ classDefinitionRepository ;
2328
29+ private ObjectBuilderFactory $ objectBuilderFactory ;
30+
2431 /** @var list<class-string> */
2532 private array $ classesWarmedUp = [];
2633
27- public function __construct (TypeParser $ parser , ClassDefinitionRepository $ classDefinitionRepository )
28- {
34+ public function __construct (
35+ TypeParser $ parser ,
36+ ObjectImplementations $ implementations ,
37+ ClassDefinitionRepository $ classDefinitionRepository ,
38+ ObjectBuilderFactory $ objectBuilderFactory
39+ ) {
2940 $ this ->parser = $ parser ;
41+ $ this ->implementations = $ implementations ;
3042 $ this ->classDefinitionRepository = $ classDefinitionRepository ;
43+ $ this ->objectBuilderFactory = $ objectBuilderFactory ;
3144 }
3245
3346 public function warmup (string ...$ signatures ): void
@@ -43,6 +56,10 @@ public function warmup(string ...$signatures): void
4356
4457 private function warmupType (Type $ type ): void
4558 {
59+ if ($ type instanceof InterfaceType) {
60+ $ this ->warmupInterfaceType ($ type );
61+ }
62+
4663 if ($ type instanceof ClassType) {
4764 $ this ->warmupClassType ($ type );
4865 }
@@ -54,6 +71,17 @@ private function warmupType(Type $type): void
5471 }
5572 }
5673
74+ private function warmupInterfaceType (InterfaceType $ type ): void
75+ {
76+ $ function = $ this ->implementations ->function ($ type ->className ());
77+
78+ $ this ->warmupType ($ function ->returnType ());
79+
80+ foreach ($ function ->parameters () as $ parameter ) {
81+ $ this ->warmupType ($ parameter ->type ());
82+ }
83+ }
84+
5785 private function warmupClassType (ClassType $ type ): void
5886 {
5987 if (in_array ($ type ->className (), $ this ->classesWarmedUp , true )) {
@@ -63,16 +91,11 @@ private function warmupClassType(ClassType $type): void
6391 $ this ->classesWarmedUp [] = $ type ->className ();
6492
6593 $ classDefinition = $ this ->classDefinitionRepository ->for ($ type );
94+ $ objectBuilders = $ this ->objectBuilderFactory ->for ($ classDefinition );
6695
67- foreach ($ classDefinition ->properties () as $ property ) {
68- $ this ->warmupType ($ property ->type ());
69- }
70-
71- foreach ($ classDefinition ->methods () as $ method ) {
72- $ this ->warmupType ($ method ->returnType ());
73-
74- foreach ($ method ->parameters () as $ parameter ) {
75- $ this ->warmupType ($ parameter ->type ());
96+ foreach ($ objectBuilders as $ builder ) {
97+ foreach ($ builder ->describeArguments () as $ argument ) {
98+ $ this ->warmupType ($ argument ->type ());
7699 }
77100 }
78101 }
0 commit comments