Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpKernel] Use TypeInfo for#[MapRequestPayload] type resolution#58036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
chalasr wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromchalasr:typeinfo-argument-resolvers

Conversation

chalasr
Copy link
Member

@chalasrchalasr commentedAug 19, 2024
edited
Loading

QA
Branch?7.2
Bug fix?no
New feature?yes
Deprecations?yes
Issues-
LicenseMIT

Simplifying mapping request parameters to object lists. Before/After:

    /**     * @param Product[] $products     */    #[Route(path: "/products", methods: "POST")]    public function __invoke(-        #[MapRequestPayload(type: Product::class)] array $products,+        #[MapRequestPayload] array $products,    ): Response {    }

/cc@yceruto@mtarld

Koc reacted with heart emoji
@carsonbotcarsonbot added this to the7.2 milestoneAug 19, 2024
@chalasrchalasrforce-pushed thetypeinfo-argument-resolvers branch 2 times, most recently from45b01c9 to7cba23bCompareAugust 20, 2024 01:40
@chalasrchalasrforce-pushed thetypeinfo-argument-resolvers branch from7cba23b to0643d9aCompareAugust 20, 2024 07:46
if ($this->typeResolver) {
$type = $this->typeResolver->resolve($parameter);

if ($type instanceof CollectionType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We have to "unwrap" a potential nullable type here I think

chalasr reacted with thumbs up emoji
@yceruto
Copy link
Member

+   /**+    * @param Product[] $products+    */    #[Route(path: "/products", methods: "POST")]    public function __invoke(-        #[MapRequestPayload(type: Product::class)] array $products,+        #[MapRequestPayload] array $products,    ): Response {    }

Honestly, when you mentioned this feature during thetype option discussion, I had higher expectations. But now that I see the diff, I’m not so sure. The combination of attributes and PHPDoc has always bothered me—things like the duplication of argument names like$products, the need for additional dependencies to make it work, and possible performance drawbacks with the current implementation make me question if it’s really worth it...

@chalasr
Copy link
MemberAuthor

I get your concern, yet that phpdoc is needed anyway for type detection in IDEs/static analyzers to work.
So we actually end up duplicating that type information in a Symfony-specific way, that's what make me think it is worth it.

dmaicher, yceruto, and Koc reacted with thumbs up emoji

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

Makes sense but IMHO:

  1. I don't think the deprecation is needed nor desired
  2. This adds advanced type resolution to the hot-path, while this info might not be used; we should look for a way to make this parsing lazy

@chalasr
Copy link
MemberAuthor

I don't think the deprecation is needed nor desired

Not strictly needed indeed but: it's not obvious what$type is about, anything else than arrays are auto detected through type declarations. That makes the API rather confusing IMHO, only for a special case that this PR is going to handles pretty much 100% of the time (#[MapRequestPayload requires serializer which requires type-info). Unneeded complexity to me. Still not convinced?

This adds advanced type resolution to the hot-path, while this info might not be used; we should look for a way to make this parsing lazy

👍 I will wrap that logic in a closure and pass it toArgumentMetadata::$type for late execution

@nicolas-grekas
Copy link
Member

Still not convinced about the deprecation :)

@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@mtarldmtarldmtarld left review comments

@ycerutoycerutoyceruto approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

6 participants
@chalasr@yceruto@nicolas-grekas@mtarld@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp