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