@@ -242,7 +242,7 @@ LiveProp Data Types
242
242
243
243
LiveProps must be a value that can be sent to JavaScript. Supported values
244
244
are scalars (int, float, string, bool, null), arrays (of scalar values), enums,
245
- DateTime objects, Doctrine entity objects, DTO , or array of DTO .
245
+ DateTime objects, Doctrine entity objects, DTOs , or array of DTOs .
246
246
247
247
See :ref: `hydration ` for handling more complex data.
248
248
@@ -622,25 +622,21 @@ Note that being able to change the "identity" of an object is something
622
622
that works only for objects that are dehydrated to a scalar value (like
623
623
persisted entities, which dehydrate to an ``id ``).
624
624
625
- Hydration, DTO's & the Serializer
625
+ Using DTO's on a LiveProp
626
626
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
627
627
628
628
.. versionadded :: 2.11
629
629
630
- Dto are now a supported type for LiveComponent
630
+ The automatic (de)hydration of DTO objects was introduced in LiveComponents 2.11.
631
631
632
- To use a ``LiveProp `` with DTO simply type properly your property
633
-
634
- .. code-block :: php
632
+ You can also use a DTO (i.e. data transfer object / any simple class) with LiveProp as long as the property has the correct type::
635
633
636
634
class ComponentWithAddressDto
637
635
{
638
636
public AddressDto $addressDto;
639
637
}
640
638
641
- And to work with DTO collection, you simply need to specified the collection type in your phpdoc
642
-
643
- .. code-block :: php
639
+ To work with a collection of DTOs, specify the collection type inside PHPDoc::
644
640
645
641
class ComponentWithAddressDto
646
642
{
@@ -650,11 +646,18 @@ And to work with DTO collection, you simply need to specified the collection typ
650
646
public array $addressDtoCollection;
651
647
}
652
648
649
+ Here is how the (de)hydration of DTO objects works:
650
+
651
+ - It finds all properties on your DTO that are readable and writable and dehydrates each one.
652
+ - the PropertyAccess component is used, which means getter and setter methods are supported, in addition to public properties.
653
+ - The DTO cannot have any constructor arguments.
654
+
653
655
If this solution doesn't feat your need
656
+
654
657
there are two others options to make this work:
655
658
656
- 1) Hydrating with the Serializer
657
- ................................
659
+ Hydrating with the Serializer
660
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
658
661
659
662
.. versionadded :: 2.8
660
663
@@ -671,8 +674,8 @@ option::
671
674
672
675
You can also set a ``serializationContext `` option on the ``LiveProp ``.
673
676
674
- 2) Hydrating with Methods: hydrateWith & dehydrateWith
675
- ......................................................
677
+ Hydrating with Methods: hydrateWith & dehydrateWith
678
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
676
679
677
680
You can take full control of the hydration process by setting the ``hydrateWith ``
678
681
and ``dehydrateWith `` options on ``LiveProp ``::
0 commit comments