Exchange::getChannel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace ETNA\Silex\Provider\RabbitMQ;
4
5
use PhpAmqpLib\Message\AMQPMessage;
6
use PhpAmqpLib\Channel\AMQPChannel;
7
/**
8
 *
9
 */
10
class Exchange
11
{
12
    private $name;
13
    private $channel;
14
    private $type        = "direct";
15
    private $passive     = false;
16
    private $durable     = false;
17
    private $auto_delete = true;
18
19
    public function __construct($name, AMQPChannel $channel, $options)
20
    {
21
        $this->name        = $name;
22
        $this->channel     = $channel;
23
        $this->type        = isset($options["type"])        ? $options["type"]        : "direct";
24
        $this->passive     = isset($options["passive"])     ? $options["passive"]     : false;
25
        $this->durable     = isset($options["durable"])     ? $options["durable"]     : true;
26
        $this->auto_delete = isset($options["auto_delete"]) ? $options["auto_delete"] : false;
27
28
        if ($name != "") {
29
            $channel->exchange_declare(
30
                $name,
31
                $this->type,
32
                $this->passive,
33
                $this->durable,
34
                $this->auto_delete
35
            );
36
        }
37
    }
38
39
    public function getName()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
40
    {
41
        return $this->name;
42
    }
43
44
    public function getChannel()
45
    {
46
        return $this->channel;
47
    }
48
49
    public function getType()
50
    {
51
        return $this->type;
52
    }
53
54
    public function isPassive()
55
    {
56
        return $this->passive;
57
    }
58
59
    public function isDurable()
60
    {
61
        return $this->durable;
62
    }
63
64
    public function isAutoDelete()
65
    {
66
        return $this->auto_delete;
67
    }
68
69
    public function send($message, $routing_key = "", $mandatory = false, $immediate = false, $ticket = null)
70
    {
71
        $message = new AMQPMessage(json_encode($message), ["Content-Type" => "application/json"]);
72
        $this->channel->basic_publish($message, $this->name, $routing_key, $mandatory, $immediate, $ticket);
73
    }
74
}
75