Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update controller.rst
  • Loading branch information
AurelienPillevesse authored Mar 12, 2024
commit 29f98a3577b58bd55f31a37a4f3594ac9580a437
16 changes: 13 additions & 3 deletions controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,18 @@ if you want to map a nested array of specific DTOs::
) {}
}

.. tip::
.. caution::

If you're using typed properties with ``MapRequestPayload```, it is
recommended to use built-in types like ``int``, ``bool`` or ``string`` for
mapping. Using custom types could expose your application implementation in
errors during denormalization. For example, validating an enum when using
``#[MapRequestPayload]`` could look like this::

If using typed properties with `MapRequestPayload`, it's recommanded to use built-in types (like `int`, `bool`, `string`...) for mapping. Using custom types can expose your application implementation outside with errors during denormalization.
Validating an Enum in your `#[MapRequestPayload]` class should look like this::
// src/Controller/LuckyController.php
use App\Model\MyInput;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;

class LuckyController
{
Expand All @@ -553,12 +561,14 @@ if you want to map a nested array of specific DTOs::
}
}

// src/Model/MyInput.php
class MyInput
{
#[Assert\Choice(callback: [MyEnum::class, 'values'])]
public string $myInputAttribute;
}

// src/Model/MyEnum.php
enum MyEnum: string
{
case FIRST_CASE = 'first_case';
Expand Down