Completed
Push — master ( e17409...9d6c1e )
by Sergey
04:06
created

LoggerDecoratedWire::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
3
namespace ButterAMQP\Debug;
4
5
use ButterAMQP\AMQP091\Framing\Frame;
6
use ButterAMQP\HeartbeatInterface;
7
use ButterAMQP\Url;
8
use ButterAMQP\WireInterface;
9
use ButterAMQP\WireSubscriberInterface;
10
use Psr\Log\LoggerAwareInterface;
11
use Psr\Log\LoggerAwareTrait;
12
use Psr\Log\LoggerInterface;
13
14
class LoggerDecoratedWire implements WireInterface, LoggerAwareInterface
15
{
16
    use LoggerAwareTrait;
17
18
    /**
19
     * @var WireInterface
20
     */
21
    private $wire;
22
23
    /**
24
     * @param WireInterface   $wire
25
     * @param LoggerInterface $logger
26
     */
27
    public function __construct(WireInterface $wire, LoggerInterface $logger)
28
    {
29
        $this->wire = $wire;
30
        $this->logger = $logger;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function setHeartbeat(HeartbeatInterface $heartbeat)
37
    {
38
        $this->wire->setHeartbeat($heartbeat);
39
40
        return $this;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function setFrameMax($frameMax)
47
    {
48
        $this->wire->setFrameMax($frameMax);
49
50
        return $this;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function open(Url $url)
57
    {
58
        $this->wire->open($url);
59
60
        return $this;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function next($blocking = true)
67
    {
68
        return $this->wire->next();
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function send(Frame $frame)
75
    {
76
        $this->logger->info(sprintf('Sending frame "%s" to channel #%d', get_class($frame), $frame->getChannel()), [
77
            'frame' => $frame,
78
        ]);
79
80
        $this->wire->send($frame);
81
82
        return $this;
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function wait($channel, $types)
89
    {
90
        $typeString = is_array($types) ? implode('", "', $types) : $types;
91
92
        $this->logger->info(sprintf('Waiting for "%s" at channel #%d', $typeString, $channel));
93
94
        return $this->wire->wait($channel, $types);
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function subscribe($channel, WireSubscriberInterface $handler)
101
    {
102
        $this->wire->subscribe($channel, $handler);
103
104
        return $this;
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110
    public function close()
111
    {
112
        $this->wire->close();
113
114
        return $this;
115
    }
116
}
117