Skip to content

[HttpKernel] Support variadic with #[MapRequestPayload]#54817

Merged
nicolas-grekas merged 1 commit intosymfony:8.1from
DjordyKoert:map-request-payload-variadic
Feb 12, 2026
Merged

[HttpKernel] Support variadic with #[MapRequestPayload]#54817
nicolas-grekas merged 1 commit intosymfony:8.1from
DjordyKoert:map-request-payload-variadic

Conversation

@DjordyKoert
Copy link
Copy Markdown
Contributor

@DjordyKoert DjordyKoert commented May 2, 2024

Q A
Branch? 7.2
Bug fix? no
New feature? yes
Deprecations? no
Issues -
License MIT

Adds support for variadic arguments in combination with #[MapRequestPayload].

Example request

Content-Type: application/json
[
    {"price": 50},
    {"price": 23}
]

Example controller usage

class MyController
{
    public function __invoke(
        #[MapRequestPayload] Price ...$prices,
    ): Response {
        // do something with $prices -> array<Price>
    }
}

This PR also fixes a bug introduced in #49978 where using #[MapUploadedFile] with a variadic argument causes a TypeError:

class MyController
{
    public function __invoke(
        #[MapUploadedFile] UploadedFile ...$documents,
    ): Response {
    }
}
Argument #1 must be of type Symfony\\Component\\HttpFoundation\\File\\UploadedFile, array given

@carsonbot carsonbot added this to the 7.1 milestone May 2, 2024
@DjordyKoert DjordyKoert force-pushed the map-request-payload-variadic branch from c08c101 to fc7b7c8 Compare May 2, 2024 12:38
@xabbuh xabbuh modified the milestones: 7.1, 7.2 May 2, 2024
@nicolas-grekas nicolas-grekas modified the milestones: 7.2, 7.1 May 16, 2024
@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
@fabpot fabpot modified the milestones: 7.3, 7.4 May 26, 2025
@nicolas-grekas nicolas-grekas modified the milestones: 7.4, 8.1 Nov 16, 2025
@symfony symfony deleted a comment from carsonbot Feb 11, 2026
@nicolas-grekas nicolas-grekas force-pushed the map-request-payload-variadic branch from fc7b7c8 to 06f4c22 Compare February 12, 2026 08:03
Copilot AI review requested due to automatic review settings February 12, 2026 08:03
@nicolas-grekas nicolas-grekas force-pushed the map-request-payload-variadic branch from 06f4c22 to 4d87be0 Compare February 12, 2026 08:06
Copy link
Copy Markdown
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rebased the PR for 8.1 and fixed a few things in the implementation.

@nicolas-grekas
Copy link
Copy Markdown
Member

Thank you @DjordyKoert.

@nicolas-grekas nicolas-grekas merged commit 1a8dbf8 into symfony:8.1 Feb 12, 2026
10 of 11 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds variadic controller argument support for #[MapRequestPayload] in HttpKernel’s controller argument resolver pipeline, and adjusts variadic handling to avoid passing arrays where individual variadic arguments are expected.

Changes:

  • Update RequestPayloadValueResolver to allow variadic mapping for #[MapRequestPayload] and expand resolved values into controller arguments.
  • Extend/adjust test coverage for variadic request payload mapping and uploaded file mapping.
  • Document the new feature in the HttpKernel changelog.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php Enables variadic payload mapping and expands variadic arguments during KernelEvents::CONTROLLER_ARGUMENTS.
src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/RequestPayloadValueResolverTest.php Adds tests for variadic #[MapRequestPayload] (form params + JSON array).
src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/UploadedFileValueResolverTest.php Updates the variadic uploaded-file test to assert the new argument shape.
src/Symfony/Component/HttpKernel/CHANGELOG.md Records the feature addition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

nicolas-grekas added a commit that referenced this pull request Feb 12, 2026
…adedFile] (nicolas-grekas)

This PR was merged into the 7.4 branch.

Discussion
----------

[HttpKernel] Fix variadic argument handling with #[MapUploadedFile]

| Q             | A
| ------------- | ---
| Branch?       | 7.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Looks like #49978 was buggy, spotted while reviewing #54817

Commits
-------

75a8c42 [HttpKernel] Fix variadic argument handling with #[MapUploadedFile]
Copy link
Copy Markdown

@edwasue-cmyk edwasue-cmyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Feb 16, 2026
…ad] (lacatoire)

This PR was merged into the 8.1 branch.

Discussion
----------

 Document variadic argument support for #[MapRequestPayload]

This documents the support for variadic arguments with `#[MapRequestPayload]`, introduced in Symfony 8.1 via symfony/symfony#54817.

## Changes

Added a code example in `controller.rst` showing that you can use a variadic argument (`UserDto ...$users`) as an alternative to the existing `array` + `type` option approach for mapping arrays of DTOs from request payloads.

Fixes #21961

Commits
-------

b575738 Document variadic argument support for #[MapRequestPayload]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants