Indicate to the Symfony Request attributes which Decoder has been used#2272
Open
damienfa wants to merge 1 commit intoFriendsOfSymfony:3.xfrom
Open
Indicate to the Symfony Request attributes which Decoder has been used#2272damienfa wants to merge 1 commit intoFriendsOfSymfony:3.xfrom
damienfa wants to merge 1 commit intoFriendsOfSymfony:3.xfrom
Conversation
A Decoder may be applied to the Request content but the application (or a third bundle used by the application), this way we're able to know if a decoder has been applied (and which).
Author
|
🙋🏻♂️ Ping here Is there any chance about this pull request ? When you create a Symfony Bundle or a library, I want to be able to know if FOSRestBundle has already done the job of "decoding" or if I have to do it by myself. |
deluxetom
approved these changes
Jan 10, 2025
Contributor
deluxetom
left a comment
There was a problem hiding this comment.
I dont think this would hurt to add this attribute 👍🏻
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context :
I'm working on a Symfony bundle. From a view, an Ajax request (application/json) is sent to a Controller managed by my bundle.
The bundle have not FOSRestBundle because we don't really want to add a new dependency in our code base (and only one Rest request).
BUT, the main Symfony application (which use our custom bundle) may be using the FOSRestBundle (and it often does).
For example, the main application could declare a Json Decoder :
My issue / question 🤔 :
The Controller, inside the bundle, doesn't really know if the Json Request received has already been "decoded" by a FOSRestBundle Json Decoder. Where can we find this information inside the Request ? (checking the app configuration is overkill I guess !).
Therefore, we manually decode the request without the help of FOSRestBundle (which is a pity because the FOSRestBundle is often present in the applications which use our custom bundle).
Exemple of code at the beggining of my Controller action :
Proposition 😃 :
The Request object have some "attributes", FOSRestBundle could add some custom metadata to tell the Request which Decoder as been used.
I propose to set the Decoder class name inside an "_fosrestbundle_decoder" Request attribute.
So, in my bundle, I will be able to easily check if FOSRestBundle has already done the job or if I have to do it by myself. 😉