Skip to content

Commit 4cc2efc

Browse files
committed
Added Lazy attribute docs
1 parent 83f214f commit 4cc2efc

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/LazyData.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,33 @@ The `createLazyUsing` method accepts a closure that returns the object.
4848
This 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+

0 commit comments

Comments
 (0)