|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Transport\Connection; |
|
5
|
|
|
|
|
6
|
|
|
use Innmind\AMQP\{ |
|
7
|
|
|
Transport\Connection as ConnectionInterface, |
|
8
|
|
|
Transport\Protocol, |
|
9
|
|
|
Transport\Frame, |
|
10
|
|
|
Model\Connection\MaxFrameSize |
|
11
|
|
|
}; |
|
12
|
|
|
use Psr\Log\LoggerInterface; |
|
13
|
|
|
|
|
14
|
|
|
final class Logger implements ConnectionInterface |
|
15
|
|
|
{ |
|
16
|
|
|
private $connection; |
|
17
|
|
|
private $logger; |
|
18
|
|
|
|
|
19
|
6 |
|
public function __construct( |
|
20
|
|
|
ConnectionInterface $connection, |
|
21
|
|
|
LoggerInterface $logger |
|
22
|
|
|
) { |
|
23
|
6 |
|
$this->connection = $connection; |
|
24
|
6 |
|
$this->logger = $logger; |
|
25
|
6 |
|
} |
|
26
|
|
|
|
|
27
|
1 |
|
public function protocol(): Protocol |
|
28
|
|
|
{ |
|
29
|
1 |
|
return $this->connection->protocol(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
1 |
|
public function send(Frame $frame): ConnectionInterface |
|
36
|
|
|
{ |
|
37
|
1 |
|
$this->logger->debug( |
|
38
|
1 |
|
'AMQP frame about to be sent', |
|
39
|
|
|
[ |
|
40
|
1 |
|
'type' => $frame->type()->toInt(), |
|
41
|
1 |
|
'channel' => $frame->channel()->toInt(), |
|
42
|
1 |
|
'binary' => (string) $frame, |
|
43
|
|
|
] |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
1 |
|
$this->connection->send($frame); |
|
47
|
1 |
|
$this->logger->debug('AMQP frame sent'); |
|
48
|
|
|
|
|
49
|
1 |
|
return $this; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritdoc} |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function wait(string ...$names): Frame |
|
56
|
|
|
{ |
|
57
|
1 |
|
$this->logger->debug('Waiting for AMQP frame', ['names' => $names]); |
|
58
|
1 |
|
$frame = $this->connection->wait(...$names); |
|
59
|
1 |
|
$this->logger->debug( |
|
60
|
1 |
|
'AMQP frame received', |
|
61
|
|
|
[ |
|
62
|
1 |
|
'type' => $frame->type()->toInt(), |
|
63
|
1 |
|
'channel' => $frame->channel()->toInt(), |
|
64
|
1 |
|
'binary' => (string) $frame, |
|
65
|
|
|
] |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
1 |
|
return $frame; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function maxFrameSize(): MaxFrameSize |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->connection->maxFrameSize(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
1 |
|
public function close(): void |
|
77
|
|
|
{ |
|
78
|
1 |
|
$this->connection->close(); |
|
79
|
1 |
|
$this->logger->debug('AMQP connection closed'); |
|
80
|
1 |
|
} |
|
81
|
|
|
|
|
82
|
1 |
|
public function closed(): bool |
|
83
|
|
|
{ |
|
84
|
1 |
|
return $this->connection->closed(); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|