Completed
Pull Request — 2.x (#2161)
by Christian
03:47
created

JMSHandlersPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.0123

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 8
cts 9
cp 0.8889
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3.0123
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\Alias;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
18
/**
19
 * Checks if the JMS serializer is available to be able to use handlers.
20
 *
21
 * @author Christian Flothmann <[email protected]>
22
 *
23
 * @internal
24
 */
25
final class JMSHandlersPass implements CompilerPassInterface
26
{
27 22
    public function process(ContainerBuilder $container)
28
    {
29 22
        if ($container->has('jms_serializer.handler_registry')) {
30
            // the public alias prevents the handler registry definition from being removed
31 6
            $container->setAlias('fos_rest.serializer.jms_handler_registry', new Alias('jms_serializer.handler_registry', true));
32
33 6
            return;
34
        }
35
36 16
        if ($container->hasDefinition('fos_rest.serializer.exception_normalizer.jms')) {
37
            $container->removeDefinition('fos_rest.serializer.exception_normalizer.jms');
38
        }
39
40 16
        $container->removeDefinition('fos_rest.serializer.handler_registry');
41 16
        $container->getParameterBag()->remove('jms_serializer.form_error_handler.class');
42 16
    }
43
}
44