Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7dea096

Browse files
committedMay 7, 2025··
review @Spomky
1 parent 647c16d commit 7dea096

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed
 

‎object-mapper.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ Object Mapper
33

44
Symfony provides a mapper component to transform a given object into another one,
55
simplifying tasks like converting DTOs (Data Transfer Objects) to entities or
6-
vice-versa.
6+
vice-versa. It may also be useful when decoupling API input/output from internal
7+
models helping with legacy code or hexagonal architectures implementations.
78

89
.. versionadded:: 7.2
910

@@ -386,7 +387,8 @@ executed *after* the target object is initially created (if the target is a
386387
class name we use ``newInstanceWithoutConstructor``) but *before* properties
387388
are mapped. Its responsibility is often to return a correctly initialized
388389
instance, potentially replacing the one created by the mapper.
389-
The returned value *must* be an object of the target type.
390+
The returned value *must* be an object of the target type or else an
391+
exception will be thrown.
390392

391393
::
392394

@@ -479,6 +481,9 @@ specifying where its properties should come from in the *source* class. This is
479481
done using the ``source`` parameter within the ``#[Map]`` attribute on the target's
480482
properties.
481483

484+
Note that if both the ``source`` and the ``target`` classes define the ``#[Map]``
485+
attribute, the ``source`` takes precedence.
486+
482487
::
483488

484489
// src/Api/Payload.php - Represents data from an external API

0 commit comments

Comments
 (0)
Please sign in to comment.