Completed
Push — master ( 0046f1...53b167 )
by
unknown
16:10 queued 06:12
created

TwigExceptionPass::process()   B

Complexity

Conditions 8
Paths 10

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 8

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 4
cts 4
cp 1
rs 8.4444
c 0
b 0
f 0
cc 8
nc 10
nop 1
crap 8
1
<?php
2
3
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\RestBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\HttpKernel\Kernel;
17
18
/**
19
 * Remove the 'fos_rest.exception.twig_controller' service if templating is not enabled and configure default exception controller.
20
 *
21
 * @internal
22
 */
23
final class TwigExceptionPass implements CompilerPassInterface
24 12
{
25
    public function process(ContainerBuilder $container)
26 12
    {
27 6
        // when no custom exception controller has been set
28 6
        if ($container->hasDefinition('fos_rest.exception_listener') &&
29 12
            null === $container->getDefinition('fos_rest.exception_listener')->getArgument(0)
30
        ) {
31
            if (isset($container->getParameter('kernel.bundles')['TwigBundle']) && $container->has('templating.engine.twig')) {
32
                // only use this when TwigBundle is enabled and the deprecated SF templating integration is used
33
                $controller = Kernel::VERSION_ID >= 40100 ? 'fos_rest.exception.twig_controller::showAction' : 'fos_rest.exception.twig_controller:showAction';
34
            } else {
35
                $controller = Kernel::VERSION_ID >= 40100 ? 'fos_rest.exception.controller::showAction' : 'fos_rest.exception.controller:showAction';
36
            }
37
38
            $container->getDefinition('fos_rest.exception_listener')->replaceArgument(0, $controller);
39
        }
40
41
        if (!$container->has('templating.engine.twig')) {
42
            $container->removeDefinition('fos_rest.exception.twig_controller');
43
        }
44
    }
45
}
46