Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions object_mapper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,48 @@
$adminProfile = $mapper->map($user, AdminUserProfile::class);
// $adminProfile->ipAddress = '192.168.1.100'

Note: When using conditions like `if: new TargetClass()`, ensure that the
source property exists. If the property does not exist, the PropertyAccess

Check failure on line 296 in object_mapper.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

Please add 4 spaces for every indention.
component may throw an exception. To avoid this, configure Symfony's
PropertyAccess component in `config/packages/framework.yaml`:

.. configuration-block::

Check failure on line 300 in object_mapper.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

Please add a blank line after ".. configuration-block::
.. code-block:: yaml

Check failure on line 301 in object_mapper.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

Please add a blank line after " .. code-block:: yaml
# config/framework.yaml
framework:
property_access:
exception_on_invalid_property_path: false

.. code-block:: xml

Check failure on line 307 in object_mapper.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

Please add a blank line after " .. code-block:: xml
<!-- config/packages/framework.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">

<framework:config>
<framework:property-access exception-on-invalid-property-path="false"/>
</framework:config>
</container>

.. code-block:: php

Check failure on line 320 in object_mapper.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

Please add a blank line after " .. code-block:: php
// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Config\FrameworkConfig;

return function(ContainerConfigurator $container): void {
$container->extension('framework', [
'property_access' => [
'exception_on_invalid_property_path' => false,
],
]);
};

This setting ensures that the mapper skips invalid properties gracefully instead
of throwing an exception.

Transforming Values
-------------------

Expand Down