File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ public static function createLazy(mixed ...$args): static
3030 }
3131
3232 return $ context ->newLazyProxy (
33- static function (mixed $ object ) use ($ context , $ value ): static {
33+ static function () use ($ context , $ value ): static {
3434 $ data = DeserializePipeline::createFromArray ()
3535 ->sendThenReturn (new DeserializePipelinePassable (
3636 classContext: $ context ,
@@ -45,4 +45,23 @@ classContext: $context,
4545 throw DataCreationException::unableToCreateLazyInstance (static ::class, $ e );
4646 }
4747 }
48+
49+ /**
50+ * @param callable(static $data): static $callable
51+ *
52+ * @throws DataCreationException
53+ */
54+ public static function createLazyUsing (callable $ callable ): static
55+ {
56+ try {
57+ /** @var ClassContext<static> $context */
58+ $ context = ClassContext::getInstance (static ::class);
59+
60+ return $ context ->newLazyProxy ($ callable );
61+ // @codeCoverageIgnoreStart
62+ } catch (Throwable $ e ) {
63+ throw DataCreationException::unableToCreateLazyInstance (static ::class, $ e );
64+ }
65+ // @codeCoverageIgnoreEnd
66+ }
4867}
Original file line number Diff line number Diff line change 22
33namespace Nuxtifyts \PhpDto \Contracts ;
44
5+ use Nuxtifyts \PhpDto \Data ;
56use Nuxtifyts \PhpDto \Exceptions \DataCreationException ;
67
78interface LazyData
@@ -10,4 +11,11 @@ interface LazyData
1011 * @throws DataCreationException
1112 */
1213 public static function createLazy (mixed ...$ args ): static ;
14+
15+ /**
16+ * @param callable(static $data): static $callable
17+ *
18+ * @throws DataCreationException
19+ */
20+ public static function createLazyUsing (callable $ callable ): static ;
1321}
You can’t perform that action at this time.
0 commit comments