|
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\Reference; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Checks if the JMS serializer is available to be able to use handlers. |
|
21
|
|
|
* |
|
22
|
|
|
* @author Christian Flothmann <[email protected]> |
|
23
|
|
|
* |
|
24
|
|
|
* @internal |
|
25
|
|
|
*/ |
|
26
|
|
|
final class JMSHandlersPass implements CompilerPassInterface |
|
27
|
|
|
{ |
|
28
|
7 |
|
public function process(ContainerBuilder $container) |
|
29
|
|
|
{ |
|
30
|
7 |
|
if ($container->has('jms_serializer.handler_registry')) { |
|
31
|
1 |
|
$this->registerHandlerRegistry($container); |
|
32
|
|
|
|
|
33
|
1 |
|
return; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
6 |
|
$container->removeDefinition('fos_rest.serializer.handler_registry'); |
|
37
|
6 |
|
$container->removeDefinition('fos_rest.serializer.exception_normalizer.jms'); |
|
38
|
6 |
|
$container->getParameterBag()->remove('jms_serializer.form_error_handler.class'); |
|
39
|
6 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Inlined because {@link JMS\SerializerBundle\DependencyInjection\Compiler\CustomHandlersPass} |
|
43
|
|
|
* must be executed before replacing jms_serializer.handler_registry. |
|
44
|
|
|
*/ |
|
45
|
1 |
|
public function registerHandlerRegistry(ContainerBuilder $container) |
|
46
|
|
|
{ |
|
47
|
1 |
|
$handlerRegistry = new Definition('FOS\RestBundle\Serializer\JMSHandlerRegistry', array(new Reference('fos_rest.serializer.jms_handler_registry'))); |
|
48
|
|
|
|
|
49
|
1 |
|
$oldRegistry = $container->getDefinition('jms_serializer.handler_registry'); |
|
50
|
1 |
|
$oldRegistry->setPublic(false); |
|
51
|
|
|
|
|
52
|
1 |
|
$container->setDefinition('jms_serializer.handler_registry', $handlerRegistry); |
|
53
|
1 |
|
$container->setDefinition('fos_rest.serializer.jms_handler_registry', $oldRegistry); |
|
54
|
1 |
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|