1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata project. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
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 Sonata\NotificationBundle\Backend; |
13
|
|
|
|
14
|
|
|
use Sonata\NotificationBundle\Model\MessageInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Base class for queue backent dispatchers. |
18
|
|
|
* |
19
|
|
|
* @author Kevin Nedelec <[email protected]> |
20
|
|
|
* |
21
|
|
|
* Class QueueBackendDispatcher |
22
|
|
|
*/ |
23
|
|
|
abstract class QueueBackendDispatcher implements QueueDispatcherInterface, BackendInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $queues; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $defaultQueue; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var BackendInterface[] |
37
|
|
|
*/ |
38
|
|
|
protected $backends; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param array $queues |
42
|
|
|
* @param string $defaultQueue |
43
|
|
|
* @param BackendInterface[] $backends |
44
|
|
|
*/ |
45
|
|
|
public function __construct(array $queues, $defaultQueue, array $backends) |
46
|
|
|
{ |
47
|
|
|
$this->queues = $queues; |
48
|
|
|
$this->backends = $backends; |
49
|
|
|
$this->defaultQueue = $defaultQueue; |
50
|
|
|
|
51
|
|
|
foreach ($this->backends as $backend) { |
52
|
|
|
$backend['backend']->setDispatcher($this); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function publish(MessageInterface $message) |
60
|
|
|
{ |
61
|
|
|
$this->getBackend($message->getType())->publish($message); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function create($type, array $body) |
68
|
|
|
{ |
69
|
|
|
return $this->getBackend($type)->create($type, $body); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
|
|
public function createAndPublish($type, array $body) |
76
|
|
|
{ |
77
|
|
|
$this->getBackend($type)->createAndPublish($type, $body); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
|
public function getQueues() |
84
|
|
|
{ |
85
|
|
|
return $this->queues; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|