Skip to content

Commit 18042fa

Browse files
committed
minor #18936 [HttpKernel] Clarify #[MapRequestPayload] with nested arrays (OskarStark)
This PR was merged into the 6.3 branch. Discussion ---------- [HttpKernel] Clarify `#[MapRequestPayload]` with nested arrays Closes #18522 I tried to rework the original PR a bit, but I am not sure about the topic if this is true. cc `@nicolas`-grekas `@Koc` Commits ------- ce5e0be Clarify MapRequestPayload with nested arrays
2 parents 0c60287 + ce5e0be commit 18042fa

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

controller.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,26 @@ payload formats::
502502
// ...
503503
}
504504

505+
Make sure to install `phpstan/phpdoc-parser`_ and `phpdocumentor/type-resolver`_
506+
if you want to map a nested array of specific DTOs::
507+
508+
public function dashboard(
509+
#[MapRequestPayload()] EmployeesDTO $employeesDto
510+
): Response
511+
{
512+
// ...
513+
}
514+
515+
final class EmployeesDTO
516+
{
517+
/**
518+
* @param UserDTO[] $users
519+
*/
520+
public function __construct(
521+
public readonly array $users = []
522+
) {}
523+
}
524+
505525
.. versionadded:: 6.3
506526

507527
The :class:`Symfony\\Component\\HttpKernel\\Attribute\\MapRequestPayload` attribute
@@ -771,3 +791,5 @@ Learn more about Controllers
771791
.. _`SAPI`: https://www.php.net/manual/en/function.php-sapi-name.php
772792
.. _`FrankenPHP`: https://frankenphp.dev
773793
.. _`Validate Filters`: https://www.php.net/manual/en/filter.filters.validate.php
794+
.. _`phpstan/phpdoc-parser`: https://packagist.org/packages/phpstan/phpdoc-parser
795+
.. _`phpdocumentor/type-resolver`: https://packagist.org/packages/phpdocumentor/type-resolver

0 commit comments

Comments
 (0)