1
1
<?php
2
2
3
3
namespace OldSound \RabbitMqBundle \RabbitMq ;
4
- <<<<<<< 5818690e0890 fb32c1d873645f59b33c73e3598c
5
- use OldSound \RabbitMqBundle \Event \AMQPEvent ;
6
- =======
7
4
8
- >>>>>>> add shutdown method. When called kernel shutdown, we must close opened connection
5
+ use OldSound \ RabbitMqBundle \ Event \ AMQPEvent ;
9
6
use PhpAmqpLib \Channel \AMQPChannel ;
10
7
use PhpAmqpLib \Connection \AbstractConnection ;
11
8
use PhpAmqpLib \Connection \AMQPLazyConnection ;
@@ -23,35 +20,35 @@ abstract class BaseAmqp
23
20
protected $ queueDeclared = false ;
24
21
protected $ routingKey = '' ;
25
22
protected $ autoSetupFabric = true ;
26
- protected $ basicProperties = [ 'content_type ' => 'text/plain ' , 'delivery_mode ' => 2 ] ;
23
+ protected $ basicProperties = array ( 'content_type ' => 'text/plain ' , 'delivery_mode ' => 2 ) ;
27
24
28
25
/**
29
26
* @var LoggerInterface
30
27
*/
31
28
protected $ logger ;
32
29
33
- protected $ exchangeOptions = [
34
- 'passive ' => false ,
35
- 'durable ' => true ,
30
+ protected $ exchangeOptions = array (
31
+ 'passive ' => false ,
32
+ 'durable ' => true ,
36
33
'auto_delete ' => false ,
37
- 'internal ' => false ,
38
- 'nowait ' => false ,
39
- 'arguments ' => null ,
40
- 'ticket ' => null ,
41
- 'declare ' => true ,
42
- ] ;
43
-
44
- protected $ queueOptions = [
45
- 'name ' => '' ,
46
- 'passive ' => false ,
47
- 'durable ' => true ,
48
- 'exclusive ' => false ,
34
+ 'internal ' => false ,
35
+ 'nowait ' => false ,
36
+ 'arguments ' => null ,
37
+ 'ticket ' => null ,
38
+ 'declare ' => true ,
39
+ ) ;
40
+
41
+ protected $ queueOptions = array (
42
+ 'name ' => '' ,
43
+ 'passive ' => false ,
44
+ 'durable ' => true ,
45
+ 'exclusive ' => false ,
49
46
'auto_delete ' => false ,
50
- 'nowait ' => false ,
51
- 'arguments ' => null ,
52
- 'ticket ' => null ,
53
- 'declare ' => true ,
54
- ] ;
47
+ 'nowait ' => false ,
48
+ 'arguments ' => null ,
49
+ 'ticket ' => null ,
50
+ 'declare ' => true ,
51
+ ) ;
55
52
56
53
/**
57
54
* @var EventDispatcherInterface
@@ -72,11 +69,7 @@ public function __construct(AbstractConnection $conn, AMQPChannel $ch = null, $c
72
69
$ this ->getChannel ();
73
70
}
74
71
75
- $ this ->consumerTag = empty ($ consumerTag ) ? sprintf (
76
- "PHPPROCESS_%s_%s " ,
77
- gethostname (),
78
- getmypid ()
79
- ) : $ consumerTag ;
72
+ $ this ->consumerTag = empty ($ consumerTag ) ? sprintf ("PHPPROCESS_%s_%s " , gethostname (), getmypid ()) : $ consumerTag ;
80
73
81
74
$ this ->logger = new NullLogger ();
82
75
}
@@ -138,12 +131,10 @@ public function setChannel(AMQPChannel $ch)
138
131
139
132
/**
140
133
* @throws \InvalidArgumentException
141
- *
142
- * @param array $options
143
- *
134
+ * @param array $options
144
135
* @return void
145
136
*/
146
- public function setExchangeOptions (array $ options = [] )
137
+ public function setExchangeOptions (array $ options = array () )
147
138
{
148
139
if (!isset ($ options ['name ' ])) {
149
140
throw new \InvalidArgumentException ('You must provide an exchange name ' );
@@ -158,17 +149,15 @@ public function setExchangeOptions(array $options = [])
158
149
159
150
/**
160
151
* @param array $options
161
- *
162
152
* @return void
163
153
*/
164
- public function setQueueOptions (array $ options = [] )
154
+ public function setQueueOptions (array $ options = array () )
165
155
{
166
156
$ this ->queueOptions = array_merge ($ this ->queueOptions , $ options );
167
157
}
168
158
169
159
/**
170
160
* @param string $routingKey
171
- *
172
161
* @return void
173
162
*/
174
163
public function setRoutingKey ($ routingKey )
@@ -218,8 +207,7 @@ protected function exchangeDeclare()
218
207
$ this ->exchangeOptions ['internal ' ],
219
208
$ this ->exchangeOptions ['nowait ' ],
220
209
$ this ->exchangeOptions ['arguments ' ],
221
- $ this ->exchangeOptions ['ticket ' ]
222
- );
210
+ $ this ->exchangeOptions ['ticket ' ]);
223
211
224
212
$ this ->exchangeDeclared = true ;
225
213
}
@@ -231,16 +219,10 @@ protected function exchangeDeclare()
231
219
protected function queueDeclare ()
232
220
{
233
221
if ($ this ->queueOptions ['declare ' ]) {
234
- list ($ queueName , ,) = $ this ->getChannel ()->queue_declare (
235
- $ this ->queueOptions ['name ' ],
236
- $ this ->queueOptions ['passive ' ],
237
- $ this ->queueOptions ['durable ' ],
238
- $ this ->queueOptions ['exclusive ' ],
239
- $ this ->queueOptions ['auto_delete ' ],
240
- $ this ->queueOptions ['nowait ' ],
241
- $ this ->queueOptions ['arguments ' ],
242
- $ this ->queueOptions ['ticket ' ]
243
- );
222
+ list ($ queueName , ,) = $ this ->getChannel ()->queue_declare ($ this ->queueOptions ['name ' ], $ this ->queueOptions ['passive ' ],
223
+ $ this ->queueOptions ['durable ' ], $ this ->queueOptions ['exclusive ' ],
224
+ $ this ->queueOptions ['auto_delete ' ], $ this ->queueOptions ['nowait ' ],
225
+ $ this ->queueOptions ['arguments ' ], $ this ->queueOptions ['ticket ' ]);
244
226
245
227
if (isset ($ this ->queueOptions ['routing_keys ' ]) && count ($ this ->queueOptions ['routing_keys ' ]) > 0 ) {
246
228
foreach ($ this ->queueOptions ['routing_keys ' ] as $ routingKey ) {
@@ -269,32 +251,6 @@ protected function queueBind($queue, $exchange, $routing_key)
269
251
}
270
252
}
271
253
272
- public function setupFabric ()
273
- {
274
- if (!$ this ->exchangeDeclared ) {
275
- $ this ->exchangeDeclare ();
276
- }
277
-
278
- if (!$ this ->queueDeclared ) {
279
- $ this ->queueDeclare ();
280
- }
281
- }
282
-
283
- /**
284
- * disables the automatic SetupFabric when using a consumer or producer
285
- */
286
- public function disableAutoSetupFabric () {
287
- $ this ->autoSetupFabric = false ;
288
- }
289
-
290
- /**
291
- * @param LoggerInterface $logger
292
- */
293
- public function setLogger ($ logger )
294
- {
295
- $ this ->logger = $ logger ;
296
- }
297
-
298
254
/**
299
255
* @param EventDispatcherInterface $eventDispatcher
300
256
*
0 commit comments