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

Symfony Flex (3.3) - Dependency with Twig #1772

Closed
matrix818181 opened this issue Oct 12, 2017 · 7 comments
Closed

Symfony Flex (3.3) - Dependency with Twig #1772

matrix818181 opened this issue Oct 12, 2017 · 7 comments

Comments

@matrix818181
Copy link

When I want to enable exception handlers, I get the following exception :

The service "fos_rest.exception.twig_controller" has a dependency on a non-existent service "templating.engine.twig".

@matrix818181 matrix818181 changed the title Symfony Flex ( - Dependency with Twig Symfony Flex (3.3 - Dependency with Twig Oct 12, 2017
@matrix818181 matrix818181 changed the title Symfony Flex (3.3 - Dependency with Twig Symfony Flex (3.3) - Dependency with Twig Oct 12, 2017
@ramoshka
Copy link

ramoshka commented Nov 7, 2017

Try adding exception_controller: 'fos_rest.exception.controller:showAction' line to your config

fos_rest:
    exception:
        enabled: true
        exception_controller: 'fos_rest.exception.controller:showAction'

If you do not define exception controller and have TwigBundle enabled fos_rest.exception.twig_controller:showAction will be used`

if ($config['exception']['exception_controller']) {

@MichaelHindley
Copy link

@ramoshka I'm seeing this error with the following config:

   exception:
      enabled: true
      exception_controller: 'AppBundle\Port\Rest\RequestValidation\RequestValidationExceptionListener::render'

It's on 3.4 though, should I open a new issue?

@xabbuh
Copy link
Member

xabbuh commented Nov 17, 2017

I guess both issues have the same cause. So no need for a new issue IMO.

@rsaenen
Copy link

rsaenen commented Dec 8, 2017

Having the same issue with Symfony 4 and Flex.

@Sharom
Copy link

Sharom commented Dec 12, 2017

Check your bundles registration order. Try to load FOSRestBundle after the TwigBundle:

 <?php
// bundles.php
return [
    // ...
    Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
    FOS\RestBundle\FOSRestBundle::class => ['all' => true],
];

It relates to the compiler pass:

namespace FOS\RestBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
 * Remove the 'fos_rest.exception.twig_controller' service if twig is enabled.
 *
 * @internal
 */
final class TwigExceptionPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        if (!$container->has('templating.engine.twig')) {
            $container->removeDefinition('fos_rest.exception.twig_controller');
        }
    }
}

If you really need to usefos_rest.exception.twig_controller, than install symfony/templating
and activate twig engine in the framework configuration:

framework:
    templating:
        engines: twig

@ahundiak
Copy link

ahundiak commented Mar 1, 2018

Given that the templating engine is no longer installed and enabled by default, why not modify the TwigExceptionPass to just check for the twig service instead of templating.engine.twig? Seem like it should still work. You lose the old style twig template path support but that should not be a problem.

@LLCDBDBBSysUser
Copy link

I have the same problem. Fix is available in #1945. Would be nice if it would get merged.

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