diff --git a/controller.rst b/controller.rst index ab14b0552d1..255ec6246c3 100644 --- a/controller.rst +++ b/controller.rst @@ -539,6 +539,47 @@ if you want to map a nested array of specific DTOs:: ) {} } +.. 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:: + + // src/Controller/LuckyController.php + use App\Model\MyInput; + use Symfony\Component\HttpFoundation\Response; + use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; + + class LuckyController + { + #[Route('/lucky/number/{max}', name: 'app_lucky_number', methods: ['POST'])] + public function number(#[MapRequestPayload] MyInput $input, int $max): Response + { + // use it like this : $input->myInputAttribute; + } + } + + // 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'; + case SECOND_CASE = 'second_case'; + + public static function values(): array + { + return array_column(self::cases(), 'value'); + } + } + Managing the Session -------------------- pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy