Completed
Push — master ( 8e37f4...bca297 )
by Asmir
12s
created

JMSSerializerBundle::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 15
cts 15
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * Copyright 2011 Johannes M. Schmitt <[email protected]>
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace JMS\SerializerBundle;
20
21
use JMS\SerializerBundle\DependencyInjection\Compiler\DoctrinePass;
22
use JMS\SerializerBundle\DependencyInjection\Compiler\TwigExtensionPass;
23
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
24
use JMS\SerializerBundle\DependencyInjection\Compiler\CustomHandlersPass;
25
use JMS\SerializerBundle\DependencyInjection\Compiler\RegisterEventListenersAndSubscribersPass;
26
use JMS\SerializerBundle\DependencyInjection\Compiler\ServiceMapPass;
27
use Symfony\Component\DependencyInjection\ContainerBuilder;
28
use Symfony\Component\HttpKernel\Bundle\Bundle;
29
use JMS\DiExtraBundle\DependencyInjection\Compiler\LazyServiceMapPass;
30
use Symfony\Component\DependencyInjection\Definition;
31
32
class JMSSerializerBundle extends Bundle
33
{
34 19
    public function build(ContainerBuilder $builder)
35
    {
36 19
        $builder->addCompilerPass($this->getServiceMapPass('jms_serializer.serialization_visitor', 'format',
37
            function(ContainerBuilder $container, Definition $def) {
38 19
                $container->getDefinition('jms_serializer.serializer')->replaceArgument(3, $def);
39 19
            }
40 19
        ));
41 19
        $builder->addCompilerPass($this->getServiceMapPass('jms_serializer.deserialization_visitor', 'format',
42 19
            function(ContainerBuilder $container, Definition $def) {
43 19
                $container->getDefinition('jms_serializer.serializer')->replaceArgument(4, $def);
44 19
            }
45 19
        ));
46
47 19
        $builder->addCompilerPass(new TwigExtensionPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
48 19
        $builder->addCompilerPass(new RegisterEventListenersAndSubscribersPass(), PassConfig::TYPE_BEFORE_REMOVING);
49 19
        $builder->addCompilerPass(new CustomHandlersPass(), PassConfig::TYPE_BEFORE_REMOVING);
50 19
        $builder->addCompilerPass(new DoctrinePass(), PassConfig::TYPE_BEFORE_REMOVING);
51 19
    }
52
53 19
    private function getServiceMapPass($tagName, $keyAttributeName, $callable)
54
    {
55 19
        if (class_exists('JMS\DiExtraBundle\DependencyInjection\Compiler\LazyServiceMapPass')) {
56
            return new LazyServiceMapPass($tagName, $keyAttributeName, $callable);
57
        }
58
59 19
        return new ServiceMapPass($tagName, $keyAttributeName, $callable);
60
    }
61
}
62