Skip to content

Commit 6e4854d

Browse files
authored
Update docs
1 parent feb1f44 commit 6e4854d

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/LiveComponent/doc/index.rst

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ LiveProp Data Types
242242

243243
LiveProps must be a value that can be sent to JavaScript. Supported values
244244
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.
246246

247247
See :ref:`hydration` for handling more complex data.
248248

@@ -622,25 +622,21 @@ Note that being able to change the "identity" of an object is something
622622
that works only for objects that are dehydrated to a scalar value (like
623623
persisted entities, which dehydrate to an ``id``).
624624

625-
Hydration, DTO's & the Serializer
625+
Using DTO's on a LiveProp
626626
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
627627

628628
.. versionadded:: 2.11
629629

630-
Dto are now a supported type for LiveComponent
630+
The automatic (de)hydration of DTO objects was introduced in LiveComponents 2.11.
631631

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::
635633

636634
class ComponentWithAddressDto
637635
{
638636
public AddressDto $addressDto;
639637
}
640638

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::
644640

645641
class ComponentWithAddressDto
646642
{
@@ -650,11 +646,18 @@ And to work with DTO collection, you simply need to specified the collection typ
650646
public array $addressDtoCollection;
651647
}
652648

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+
653655
If this solution doesn't feat your need
656+
654657
there are two others options to make this work:
655658

656-
1) Hydrating with the Serializer
657-
................................
659+
Hydrating with the Serializer
660+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
658661

659662
.. versionadded:: 2.8
660663

@@ -671,8 +674,8 @@ option::
671674

672675
You can also set a ``serializationContext`` option on the ``LiveProp``.
673676

674-
2) Hydrating with Methods: hydrateWith & dehydrateWith
675-
......................................................
677+
Hydrating with Methods: hydrateWith & dehydrateWith
678+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
676679

677680
You can take full control of the hydration process by setting the ``hydrateWith``
678681
and ``dehydrateWith`` options on ``LiveProp``::

0 commit comments

Comments
 (0)