@@ -31,14 +31,20 @@ final public static function create(mixed ...$args): static
3131 throw DataCreationException::invalidParamsPassed (static ::class);
3232 }
3333
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 ();
4248 } catch (Throwable $ e ) {
4349 throw DataCreationException::unableToCreateInstance (static ::class, $ e );
4450 }
@@ -59,16 +65,22 @@ final public static function from(mixed $value): static
5965 throw DeserializeException::invalidValue ();
6066 }
6167
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 ();
7284 } catch (Throwable $ e ) {
7385 throw DeserializeException::generic ($ e );
7486 }
0 commit comments