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

enable jms max depth exclusion strategy #851

Closed
wants to merge 1 commit into from
Closed

enable jms max depth exclusion strategy #851

wants to merge 1 commit into from

Conversation

jbouzekri
Copy link

It adds a call to the ViewHandler to enable the max depth strategy exclusion in jms serializer context.

Best regards

@lsmith77
Copy link
Member

so the actual max depth will then still need to be set on the context by the user?

@jbouzekri
Copy link
Author

Not exactly, the user enable this jms context feature by setting in a parameters.yml file :

fos_rest.serializer.exclusion_strategy.max_depth: true

Then he can use the max_depth property in his JMS configuration. For example, in the file MyBundle/Resources/config/serializer/Item.yml :

MyBundle\Entity\Item:
    exclusion_policy: ALL
    properties:
        children:
            expose: true
            max_depth: 3

@lsmith77
Copy link
Member

ok .. but this config should then be added to the DI extension. furthermore please also add some infos to the docs on this. finally please also add a test case.

@jbouzekri
Copy link
Author

Yeah I wanted to see if this pull request was acceptable. For the DIC extension, my bad, I just saw that there was a serializer section. Ok I will work on it shortly.

@jbouzekri
Copy link
Author

What an idiot I am. I just made a search on MaxDepth and I found that this feature was implemented for the View using annotation.

/**
 * @View(
 *  serializerEnableMaxDepthChecks=false
 * )
 */

After looking at what happens in the ViewResponseListener, I have created a CustomView extending the normal View and overrided the create static method and use it in my controllers (as I don't like annotation) :

use FOS\RestBundle\View\View as BaseView;

class View extends BaseView
{
    /**
     * {@inheritDoc}
     */
    public static function create($data = null, $statusCode = null, array $headers = array())
    {
        $view = parent::create($data, $statusCode, $headers);
        $view->getSerializationContext()->enableMaxDepthChecks();
        return $view;
    }
}

So i will close this pull request. Thanks for your time.

@jbouzekri jbouzekri closed this Aug 26, 2014
@jbouzekri jbouzekri deleted the jms_max_depth branch August 26, 2014 20:39
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

Successfully merging this pull request may close these issues.

None yet

2 participants