File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -48,3 +48,33 @@ The `createLazyUsing` method accepts a closure that returns the object.
4848This closure will be called only once, and the object will be cached for future calls.
4949
5050> For more information about lazy objects. Please refer to the [ PHP documentation] ( https://www.php.net/manual/en/language.oop5.lazy-objects.php ) .
51+
52+ Lazy Data Attribute
53+ -
54+
55+ Sometimes we may want to enable lazy data for a specific ` Data ` class.
56+ In order to do that, we can user the ` Lazy ` attribute.
57+
58+ ``` php
59+ use Nuxtifyts\PhpDto\Data;
60+ use Nuxtifyts\PhpDto\Attributes\Class\Lazy;
61+
62+ #[Lazy]
63+ final readonly class UserData extends Data
64+ {
65+ public function __construct(
66+ public int $id,
67+ public string $firstName,
68+ public string $lastName
69+ ) {}
70+ }
71+ ```
72+
73+ This will enable lazy data for all the "essential" functions that ` Data ` provides:
74+ [ create] ( https://github.com/nuxtifyts/php-dto/blob/main/docs/DefaultValues.md ) ,
75+ [ from] ( https://github.com/nuxtifyts/php-dto/blob/main/docs/Quickstart.md ) ,
76+ [ empty] ( https://github.com/nuxtifyts/php-dto/blob/main/docs/EmptyData.md )
77+ and [ clone] ( https://github.com/nuxtifyts/php-dto/blob/main/docs/CloneableData.md ) .
78+
79+
80+
You can’t perform that action at this time.
0 commit comments