@@ -31,14 +31,20 @@ final public static function create(mixed ...$args): static
31
31
throw DataCreationException::invalidParamsPassed (static ::class);
32
32
}
33
33
34
- $ data = DeserializePipeline::createFromArray ()
35
- ->sendThenReturn (new DeserializePipelinePassable (
36
- classContext: $ context ,
37
- data: $ value
38
- ))
39
- ->data ;
40
-
41
- return $ context ->constructFromArray ($ data );
34
+ $ dataCreationClosure = static function () use ($ context , $ value ): static {
35
+ $ data = DeserializePipeline::createFromArray ()
36
+ ->sendThenReturn (new DeserializePipelinePassable (
37
+ classContext: $ context ,
38
+ data: $ value
39
+ ))
40
+ ->data ;
41
+
42
+ return $ context ->constructFromArray ($ data );
43
+ };
44
+
45
+ return $ context ->isLazy
46
+ ? $ context ->newLazyProxy ($ dataCreationClosure )
47
+ : $ dataCreationClosure ();
42
48
} catch (Throwable $ e ) {
43
49
throw DataCreationException::unableToCreateInstance (static ::class, $ e );
44
50
}
@@ -59,16 +65,22 @@ final public static function from(mixed $value): static
59
65
throw DeserializeException::invalidValue ();
60
66
}
61
67
62
- $ data = DeserializePipeline::hydrateFromArray ()
63
- ->sendThenReturn (new DeserializePipelinePassable (
64
- classContext: $ context ,
65
- data: $ value
66
- ))
67
- ->data ;
68
-
69
- return $ context ->hasComputedProperties
70
- ? $ context ->constructFromArray ($ data )
71
- : static ::instanceWithoutConstructorFrom ($ context , $ data );
68
+ $ dataCreationClosure = static function () use ($ context , $ value ): static {
69
+ $ data = DeserializePipeline::hydrateFromArray ()
70
+ ->sendThenReturn (new DeserializePipelinePassable (
71
+ classContext: $ context ,
72
+ data: $ value
73
+ ))
74
+ ->data ;
75
+
76
+ return $ context ->hasComputedProperties
77
+ ? $ context ->constructFromArray ($ data )
78
+ : static ::instanceWithoutConstructorFrom ($ context , $ data );
79
+ };
80
+
81
+ return $ context ->isLazy
82
+ ? $ context ->newLazyProxy ($ dataCreationClosure )
83
+ : $ dataCreationClosure ();
72
84
} catch (Throwable $ e ) {
73
85
throw DeserializeException::generic ($ e );
74
86
}
0 commit comments