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