-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Cookbook adding after filter using kernel.response listener (issue #649) #1653
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
||
So, after generating a JSON response, this hash has to be added to the response. | ||
|
||
Before and after filters with kernel.controller / kernel.response events |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it better to place this in a inline code block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry I don't understand what you mean here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ricardclau I mean something like this:
Before and after filters with ``kernel.controller``/``kernel.response`` events
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sure, sorry :)
Your example is a bad one IMO. If you use a custom response class, you can do this without using a listener (simply overwrite |
@wouterj I have 2 doubts regarding your catchs, comments added after yours @stof Note that I am using the token in the request as a salt for the sha1. I don't think this can be cleanly done overwriting setContent. Moreover, the idea of using the Listener is not just for a simple hash, it is to make people aware that another "hashing service" could be injected and do some more complicated stuff after creating and returning the Response in the controller. Anyway, if there are more -1 I can revert this, but I still think it is not a bad example. Any opinions? |
@ricardclau then I would use an example which does not use a custom Response class, as I'm quite sure some people will think that this pattern is not usable without doing it too. |
@stof I am using a custom Reponse class as a way to "tag" it, so that changing the response only gets executed in that type of responses and not all of them (actually analog to the before filter example). The pattern is usable without extending Response but it would get executed for all Responses and you don't want that most of the times I guess. Anyway, I am open to change any thing you want to make the example more useful, so I am open to suggestions! |
…efore part and the after part
Hi guys! I really like this entry - takes a fairly non-technical question of how to have before/after filters and gives it a technical answer. I did make one change where I separated the before and after filters into 2 different sections to be clear about how each piece works independently. I also changed how we flagged a request to be hashed by using the request's attributes bag instead of the custom Response. Again, this was just to try to "minimize" things as much as possible so that the true important parts of the entry standout. If anyone has any thoughts, fixes or complaints with this final version, please let me know! Thanks Ricard for finishing up this entry! |
This is the second part on the cookbook about setting before and after filters using Symfony2 Event Listeners. Sorry for the BIG delay about it, but as they say better later than never :)
Any typos and errors detected will be more than welcome!
Best regards