|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Gendoria\CommandQueueBundle\DependencyInjection\Pass; |
|
4
|
|
|
|
|
5
|
|
|
use Gendoria\CommandQueue\Serializer\NullSerializer; |
|
6
|
|
|
use Gendoria\CommandQueueBundle\Serializer\JmsSerializer; |
|
7
|
|
|
use Gendoria\CommandQueueBundle\Serializer\SymfonySerializer; |
|
8
|
|
|
use JMS\SerializerBundle\JMSSerializerBundle; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
13
|
|
|
use Symfony\Component\Serializer\Serializer; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Description of RegisterDriversPass |
|
17
|
|
|
* |
|
18
|
|
|
* @author Tomasz Struczyński <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
class RegisterSerializerDriversPass implements CompilerPassInterface |
|
21
|
|
|
{ |
|
22
|
2 |
|
public function process(ContainerBuilder $container) |
|
23
|
|
|
{ |
|
24
|
2 |
|
$this->registerNullDriver($container); |
|
25
|
2 |
|
$this->registerSymfonyDriver($container); |
|
26
|
2 |
|
$this->registerJmsDriver($container); |
|
27
|
2 |
|
} |
|
28
|
|
|
|
|
29
|
2 |
|
private function registerNullDriver(ContainerBuilder $container) |
|
30
|
|
|
{ |
|
31
|
2 |
|
$container->addDefinitions(array( |
|
32
|
2 |
|
'gendoria_command_queue.serializer.null' => new Definition(NullSerializer::class), |
|
33
|
2 |
|
)); |
|
34
|
2 |
|
} |
|
35
|
|
|
|
|
36
|
2 |
|
private function registerSymfonyDriver(ContainerBuilder $container) |
|
37
|
|
|
{ |
|
38
|
2 |
|
if (class_exists(Serializer::class) && $container->hasDefinition('serializer')) { |
|
39
|
1 |
|
$definition = new Definition(SymfonySerializer::class); |
|
40
|
1 |
|
$definition->addArgument(new Reference('serializer')); |
|
41
|
1 |
|
$container->addDefinitions(array('gendoria_command_queue.serializer.symfony' => $definition)); |
|
42
|
1 |
|
} |
|
43
|
2 |
|
} |
|
44
|
|
|
|
|
45
|
2 |
|
private function registerJmsDriver(ContainerBuilder $container) |
|
46
|
|
|
{ |
|
47
|
2 |
|
if (class_exists(JMSSerializerBundle::class)) { |
|
48
|
2 |
|
$definition = new Definition(JmsSerializer::class); |
|
49
|
2 |
|
$definition->addArgument(new Reference('jms_serializer')); |
|
50
|
2 |
|
$container->addDefinitions(array('gendoria_command_queue.serializer.jms' => $definition)); |
|
51
|
2 |
|
} |
|
52
|
|
|
} |
|
53
|
|
|
} |