Skip to content
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

PreSerialize + Groups #471

Closed
pe77 opened this issue Jul 24, 2015 · 3 comments
Closed

PreSerialize + Groups #471

pe77 opened this issue Jul 24, 2015 · 3 comments

Comments

@pe77
Copy link

pe77 commented Jul 24, 2015

Hey bro!

I can use Groups and Preserialize at same time?

For example, in my case:

    /**
     * @JMS\PreSerialize
     * @JMS\Groups({"Admin"})
     */
    public function onPreSerialize()
    {
     ...

Just don't work. The group ignored. The function is always called.

I could not tell if this is just a problem. Anyway, is there anything I can do?

@rodrigorigotti
Copy link

You can create a subscriber which extends the JMS\Serializer\EventDispatcher\EventSubscriverInterface and create the onPreSerialize method, which receives the JMS\Serialzier\EventDispatcher\PreSerializeEvent event object.

Then use the following method to get access to the current request's groups:

$event->getContext()->attributes->get('groups')->get()

@pe77
Copy link
Author

pe77 commented Aug 6, 2015

Thanks! Work perfectly!!!

@pe77 pe77 closed this as completed Aug 6, 2015
@elvispdosreis
Copy link

Could you give me an example of how to implement this I'm having the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants