Skip to content

FOSRest namespace is not defined and argument #2 must be of type array #2409

Open
@flohw

Description

@flohw

Hello there,

As discussed in #2400 I looked at the error a bit longer this morning and preferred to open an issue for better tracking instead of continuing the thread there. The exception is raised when sensio extra bundle is installed and the controller returns an object which is expected to be serialized by the bundle but is passed to twig instead.

I can confirm that by reverting the weight to 30 on kernel view event it fixes the issue.

The reason is because the View attribute extends the Template class if it exists (which exists because sensio extra bundle is installed (check made line 16 of View)

As the TemplateListener of the extra bundle has a higher priority than the ViewResponseListener, the Template listener tries to render the template defined by the template guesser (line 71 of TemplateListener) the guesser uses bundle's name, route, controller to define a name (I guess, I didn't looked at it as it's not relevant for us) that's why we get the exception FOSRest namespace is not defined.

The other exception is raised because the $parameters returned by the controller are expected to be an array of variables passed to a twig render method which FOSRest used to bypass with its ViewResponseListener (which serialize the controller response so the TemplateListener can't be used (line 85 returns true so return l86 is invoked)

I think I can provide a patch but not sure about the test strategy: should I only test the event weight with a comment or should I create a functional test which would trigger that particular case and resolve by changing the event weight?

Before providing the patch, it would be nice if someone else could double check what I explained if I didn't misunderstood the code or missed something else aka I don't have the right explanation of the bug as I'm not an expert of the whole bundle. 🙂

Thanks 🙂

ping to @mbabker and @benconda as you were the latest involved in the discussion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions