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\AMQP091\WireInterface; |
9
|
|
|
use ButterAMQP\AMQP091\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
|
8 |
|
public function __construct(WireInterface $wire, LoggerInterface $logger) |
28
|
|
|
{ |
29
|
8 |
|
$this->wire = $wire; |
30
|
8 |
|
$this->logger = $logger; |
31
|
8 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
1 |
|
public function setHeartbeat(HeartbeatInterface $heartbeat) |
37
|
|
|
{ |
38
|
1 |
|
$this->wire->setHeartbeat($heartbeat); |
39
|
|
|
|
40
|
1 |
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
1 |
|
public function setFrameMax($frameMax) |
47
|
|
|
{ |
48
|
1 |
|
$this->wire->setFrameMax($frameMax); |
49
|
|
|
|
50
|
1 |
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
1 |
|
public function open(Url $url) |
57
|
|
|
{ |
58
|
1 |
|
$this->wire->open($url); |
59
|
|
|
|
60
|
1 |
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
1 |
|
public function next($blocking = true) |
67
|
|
|
{ |
68
|
1 |
|
return $this->wire->next(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
1 |
|
public function send(Frame $frame) |
75
|
|
|
{ |
76
|
1 |
|
$this->logger->info(sprintf('Sending frame "%s" to channel #%d', get_class($frame), $frame->getChannel()), [ |
77
|
1 |
|
'frame' => $frame, |
78
|
1 |
|
]); |
79
|
|
|
|
80
|
1 |
|
$this->wire->send($frame); |
81
|
|
|
|
82
|
1 |
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
1 |
|
public function wait($channel, $types) |
89
|
|
|
{ |
90
|
1 |
|
$typeString = is_array($types) ? implode('", "', $types) : $types; |
91
|
|
|
|
92
|
1 |
|
$this->logger->info(sprintf('Waiting for "%s" at channel #%d', $typeString, $channel)); |
93
|
|
|
|
94
|
1 |
|
return $this->wire->wait($channel, $types); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
1 |
|
public function subscribe($channel, WireSubscriberInterface $handler) |
101
|
|
|
{ |
102
|
1 |
|
$this->wire->subscribe($channel, $handler); |
103
|
|
|
|
104
|
1 |
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* {@inheritdoc} |
109
|
|
|
*/ |
110
|
1 |
|
public function close() |
111
|
|
|
{ |
112
|
1 |
|
$this->wire->close(); |
113
|
|
|
|
114
|
1 |
|
return $this; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|