Completed
Push — 2.x-dev-kit ( 8d77e1 )
by
unknown
28:22 queued 25:50
created

QueueBackendDispatcher   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 5
Bugs 2 Features 1
Metric Value
wmc 6
c 5
b 2
f 1
lcom 1
cbo 2
dl 0
loc 65
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A publish() 0 4 1
A create() 0 4 1
A createAndPublish() 0 4 1
A getQueues() 0 4 1
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