/
JMSSerializerBundle.php
49 lines (43 loc) · 2.52 KB
/
JMSSerializerBundle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace JMS\SerializerBundle;
use JMS\DiExtraBundle\DependencyInjection\Compiler\LazyServiceMapPass;
use JMS\SerializerBundle\DependencyInjection\Compiler\CustomHandlersPass;
use JMS\SerializerBundle\DependencyInjection\Compiler\DoctrinePass;
use JMS\SerializerBundle\DependencyInjection\Compiler\ExpressionFunctionProviderPass;
use JMS\SerializerBundle\DependencyInjection\Compiler\FormErrorHandlerTranslationDomainPass;
use JMS\SerializerBundle\DependencyInjection\Compiler\RegisterEventListenersAndSubscribersPass;
use JMS\SerializerBundle\DependencyInjection\Compiler\ServiceMapPass;
use JMS\SerializerBundle\DependencyInjection\Compiler\TwigExtensionPass;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class JMSSerializerBundle extends Bundle
{
public function build(ContainerBuilder $builder)
{
$builder->addCompilerPass($this->getServiceMapPass('jms_serializer.serialization_visitor', 'format',
function (ContainerBuilder $container, $def) {
$container->getDefinition('jms_serializer.serializer')->replaceArgument(2, $def);
}
));
$builder->addCompilerPass($this->getServiceMapPass('jms_serializer.deserialization_visitor', 'format',
function (ContainerBuilder $container, $def) {
$container->getDefinition('jms_serializer.serializer')->replaceArgument(3, $def);
}
));
$builder->addCompilerPass(new FormErrorHandlerTranslationDomainPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
$builder->addCompilerPass(new TwigExtensionPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
$builder->addCompilerPass(new ExpressionFunctionProviderPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
$builder->addCompilerPass(new RegisterEventListenersAndSubscribersPass(), PassConfig::TYPE_BEFORE_REMOVING);
$builder->addCompilerPass(new CustomHandlersPass(), PassConfig::TYPE_BEFORE_REMOVING);
$builder->addCompilerPass(new DoctrinePass(), PassConfig::TYPE_BEFORE_REMOVING);
}
private function getServiceMapPass($tagName, $keyAttributeName, $callable)
{
if (class_exists('JMS\DiExtraBundle\DependencyInjection\Compiler\LazyServiceMapPass')) {
return new LazyServiceMapPass($tagName, $keyAttributeName, $callable);
}
return new ServiceMapPass($tagName, $keyAttributeName, $callable);
}
}