Skip to content

VIewHandler can't accept Twig in Symfony 4.3 and beyond #2020

Closed
@sarcher

Description

After upgrading to Symfony 4.3, it appears impossible to both avoid deprecation notices and use Twig as the default render engine for the ViewHandler class. This message is seen:

An instance of Symfony\Component\Templating\EngineInterface must be injected in
FOS\RestBundle\View\ViewHandler to render templates.

Since the constructor for ViewHandler type hints an EngineInterface , the following configuration will fail because Twig is now an instance of Twig\Environment:

fos_rest:
    service:
        templating: twig

One workaround is to extend the ViewHandler class and then replace the default implementation, but this seems like an ugly necessity to use things in their (more or less) default setup.

So, either I am missing something, or there needs to be a fix here. My best guess would be to remove the type hint and add a check to see that the injected object is either Twig\Environment or an instance of EngineInterface or null.

I feel like I am missing something, though, since this was not mentioned in the other deprecation fixes. Is there another solution here?

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