Code

< 40 %
40-60 %
> 60 %
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\DiExtraBundle\DependencyInjection\Compiler\LazyServiceMapPass;
22
use JMS\SerializerBundle\DependencyInjection\Compiler\CustomHandlersPass;
23
use JMS\SerializerBundle\DependencyInjection\Compiler\DoctrinePass;
24
use JMS\SerializerBundle\DependencyInjection\Compiler\FormErrorHandlerTranslationDomainPass;
25
use JMS\SerializerBundle\DependencyInjection\Compiler\RegisterEventListenersAndSubscribersPass;
26
use JMS\SerializerBundle\DependencyInjection\Compiler\ServiceMapPass;
27
use JMS\SerializerBundle\DependencyInjection\Compiler\TwigExtensionPass;
28
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
29
use Symfony\Component\DependencyInjection\ContainerBuilder;
30
use Symfony\Component\DependencyInjection\Definition;
31
use Symfony\Component\HttpKernel\Bundle\Bundle;
32
33
class JMSSerializerBundle extends Bundle
34
{
35 25
    public function build(ContainerBuilder $builder)
36
    {
37 25
        $builder->addCompilerPass($this->getServiceMapPass('jms_serializer.serialization_visitor', 'format',
38
            function (ContainerBuilder $container, Definition $def) {
39 25
                $container->getDefinition('jms_serializer.serializer')->replaceArgument(3, $def);
40 25
            }
41 25
        ));
42 25
        $builder->addCompilerPass($this->getServiceMapPass('jms_serializer.deserialization_visitor', 'format',
43 25
            function (ContainerBuilder $container, Definition $def) {
44 25
                $container->getDefinition('jms_serializer.serializer')->replaceArgument(4, $def);
45 25
            }
46 25
        ));
47
48 25
        $builder->addCompilerPass(new FormErrorHandlerTranslationDomainPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
49 25
        $builder->addCompilerPass(new TwigExtensionPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
50 25
        $builder->addCompilerPass(new RegisterEventListenersAndSubscribersPass(), PassConfig::TYPE_BEFORE_REMOVING);
51 25
        $builder->addCompilerPass(new CustomHandlersPass(), PassConfig::TYPE_BEFORE_REMOVING);
52 25
        $builder->addCompilerPass(new DoctrinePass(), PassConfig::TYPE_BEFORE_REMOVING);
53 25
    }
54
55 25
    private function getServiceMapPass($tagName, $keyAttributeName, $callable)
56
    {
57 25
        if (class_exists('JMS\DiExtraBundle\DependencyInjection\Compiler\LazyServiceMapPass')) {
58
            return new LazyServiceMapPass($tagName, $keyAttributeName, $callable);
59
        }
60
61 25
        return new ServiceMapPass($tagName, $keyAttributeName, $callable);
62
    }
63
}
64