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
|
|
|
{ |
25
|
22 |
|
public function process(ContainerBuilder $container) |
26
|
|
|
{ |
27
|
|
|
// when no custom exception controller has been set |
28
|
22 |
|
if ($container->hasDefinition('fos_rest.error_listener') && |
29
|
22 |
|
null === $container->getDefinition('fos_rest.error_listener')->getArgument(0) |
30
|
|
|
) { |
31
|
2 |
|
if (isset($container->getParameter('kernel.bundles')['TwigBundle']) && ($container->has('templating.engine.twig') || $container->has('twig'))) { |
32
|
|
|
// only use this when TwigBundle is enabled and the deprecated SF templating integration is used |
33
|
1 |
|
$controller = Kernel::VERSION_ID >= 40100 ? 'fos_rest.exception.twig_controller::showAction' : 'fos_rest.exception.twig_controller:showAction'; |
34
|
|
|
} else { |
35
|
1 |
|
$controller = Kernel::VERSION_ID >= 40100 ? 'fos_rest.exception.controller::showAction' : 'fos_rest.exception.controller:showAction'; |
36
|
|
|
} |
37
|
|
|
|
38
|
2 |
|
$container->getDefinition('fos_rest.error_listener')->replaceArgument(0, $controller); |
39
|
|
|
} |
40
|
|
|
|
41
|
22 |
|
if (!$container->has('templating.engine.twig')) { |
42
|
20 |
|
if ($container->has('twig') && $container->has('fos_rest.exception.twig_controller')) { |
43
|
5 |
|
$container->findDefinition('fos_rest.exception.twig_controller')->replaceArgument(3, $container->findDefinition('twig')); |
44
|
|
|
} else { |
45
|
15 |
|
$container->removeDefinition('fos_rest.exception.twig_controller'); |
46
|
|
|
} |
47
|
|
|
} |
48
|
22 |
|
} |
49
|
|
|
} |
50
|
|
|
|