Hi,
I created a service that listens to the kernel.response event and that adds
some data to JSON responses before the response is sent to the browser.
However, I need to decode the response content before encoding it again,
which is not very beautiful:
public function onKernelResponse(FilterResponseEvent $event)
> {
> $response = $event->getResponse();
> if ($response instanceof JsonResponse) {
> $data = json_decode($response->getContent());
> // ... Add new entries to data array
> $response->setData($data);
> }
> }
Wouldn't it be a good idea to keep the non-encoded response data in a class
property when calling the setData($data) method?
In that case, the $data class property would store the given data instead
of the encoded content, and the content could be either available in an
other property or computed in an overridden getContent() method that would
encode the data before returning it.
What do you think about it?
--
--
If you want to report a vulnerability issue on Symfony, please read the
procedure on http://symfony.com/security
You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
---
You received this message because you are subscribed to the Google Groups
"Symfony developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.