1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cmobi\RabbitmqBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Cmobi\RabbitmqBundle\DependencyInjection\Compiler\LogDispatcherPass; |
6
|
|
|
use Cmobi\RabbitmqBundle\DependencyInjection\Compiler\RpcServerPass; |
7
|
|
|
use Cmobi\RabbitmqBundle\DependencyInjection\Compiler\SubscriberPass; |
8
|
|
|
use Cmobi\RabbitmqBundle\DependencyInjection\Compiler\WorkerPass; |
9
|
|
|
use Symfony\Component\Config\FileLocator; |
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
11
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
12
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
13
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
14
|
|
|
|
15
|
|
|
class CmobiRabbitmqExtension extends Extension |
16
|
|
|
{ |
17
|
|
|
public function load(array $configs, ContainerBuilder $container) |
18
|
|
|
{ |
19
|
|
|
$fileLocator = new FileLocator(__DIR__ . '/../Resources/config'); |
20
|
|
|
$loader = new YamlFileLoader($container, $fileLocator); |
21
|
|
|
$loader->load('rabbitmq.yml'); |
22
|
|
|
|
23
|
|
|
$configuration = $this->getConfiguration($configs, $container); |
24
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
|
|
|
25
|
|
|
$this->registerLogger($container, $configs[0]['log_path']); |
26
|
|
|
$this->loadConnections($container, $configs[0]); |
27
|
|
|
$this->loadRpcServers($container, $config); |
28
|
|
|
$this->loadWorkers($container, $config); |
29
|
|
|
|
30
|
|
|
/* Compile and lock container */ |
31
|
|
|
$container->compile(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function loadConnections(ContainerBuilder $container, array $configs) |
35
|
|
|
{ |
36
|
|
|
$factories = []; |
37
|
|
|
|
38
|
|
|
foreach ($configs['connections'] as $name => $connection) { |
39
|
|
|
$connectionClass = '%cmobi_rabbitmq.connection.class%'; |
40
|
|
|
|
41
|
|
|
if ($connection['lazy']) { |
42
|
|
|
$connectionClass = '%cmobi_rabbitmq.lazy.connection.class%'; |
43
|
|
|
} |
44
|
|
|
$definition = new Definition( |
45
|
|
|
'%cmobi_rabbitmq.connection.factory.class%', |
46
|
|
|
[ |
47
|
|
|
$connectionClass, |
48
|
|
|
$connection, |
49
|
|
|
] |
50
|
|
|
); |
51
|
|
|
$factoryName = sprintf('cmobi_rabbitmq.connection.factory.%s', $name); |
52
|
|
|
$container->setDefinition($factoryName, $definition); |
53
|
|
|
$factories[$name] = $factoryName; |
54
|
|
|
} |
55
|
|
|
$container->setParameter('cmobi_rabbitmq.connection.factories', $factories); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
View Code Duplication |
public function loadRpcServers(ContainerBuilder $container, array $configs) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
foreach ($configs['rpc_servers'] as $server) { |
61
|
|
|
|
62
|
|
|
$container->addCompilerPass(new RpcServerPass( |
63
|
|
|
$server['queue']['name'], |
64
|
|
|
$server['queue']['connection'], |
65
|
|
|
$server['service'], |
66
|
|
|
$server['queue']['basic_qos'], |
67
|
|
|
$server['queue']['durable'], |
68
|
|
|
$server['queue']['auto_delete'], |
69
|
|
|
$server['queue']['arguments'] |
70
|
|
|
)); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function loadWorkers(ContainerBuilder $container, array $configs) |
75
|
|
|
{ |
76
|
|
|
foreach ($configs['workers'] as $worker) { |
77
|
|
|
$container->addCompilerPass(new WorkerPass( |
78
|
|
|
$worker['queue']['name'], |
79
|
|
|
$worker['queue']['connection'], |
80
|
|
|
$worker['service'], |
81
|
|
|
$worker['queue']['basic_qos'], |
82
|
|
|
$worker['queue']['arguments'] |
83
|
|
|
)); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
View Code Duplication |
public function loadSubscribers(ContainerBuilder $container, array $configs) |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
foreach ($configs['subscribers'] as $subscriber) { |
90
|
|
|
$container->addCompilerPass(new SubscriberPass( |
91
|
|
|
$subscriber['queue']['exchange'], |
92
|
|
|
$subscriber['queue']['exchange_type'], |
93
|
|
|
$subscriber['queue']['name'], |
94
|
|
|
$subscriber['queue']['connection'], |
95
|
|
|
$subscriber['service'], |
96
|
|
|
$subscriber['queue']['basic_qos'], |
97
|
|
|
$subscriber['queue']['arguments'] |
98
|
|
|
)); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param ContainerBuilder $container |
104
|
|
|
* @param $path |
105
|
|
|
*/ |
106
|
|
|
public function registerLogger(ContainerBuilder $container, $path) |
107
|
|
|
{ |
108
|
|
|
$logDispatcherPass = new LogDispatcherPass($path); |
109
|
|
|
$container->addCompilerPass($logDispatcherPass); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: