1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ButterAMQP\Debug; |
4
|
|
|
|
5
|
|
|
use ButterAMQP\IOInterface; |
6
|
|
|
use Psr\Log\LoggerInterface; |
7
|
|
|
|
8
|
|
|
class LoggerDecoratedIO implements IOInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var IOInterface |
12
|
|
|
*/ |
13
|
|
|
private $io; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var LoggerInterface |
17
|
|
|
*/ |
18
|
|
|
private $logger; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param IOInterface $io |
22
|
|
|
* @param LoggerInterface $logger |
23
|
|
|
*/ |
24
|
5 |
|
public function __construct(IOInterface $io, LoggerInterface $logger) |
25
|
|
|
{ |
26
|
5 |
|
$this->io = $io; |
27
|
5 |
|
$this->logger = $logger; |
28
|
5 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
1 |
|
public function open($protocol, $host, $port, array $parameters = []) |
34
|
|
|
{ |
35
|
1 |
|
$this->logger->debug(sprintf('Connecting to "%s://%s:%d"...', $protocol, $host, $port), [ |
36
|
1 |
|
'protocol' => $protocol, |
37
|
1 |
|
'host' => $host, |
38
|
1 |
|
'port' => $port, |
39
|
1 |
|
'parameters' => $parameters, |
40
|
1 |
|
]); |
41
|
|
|
|
42
|
1 |
|
return $this->io->open($protocol, $host, $port, $parameters); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
1 |
|
public function close() |
49
|
|
|
{ |
50
|
1 |
|
$this->logger->debug('Closing connection'); |
51
|
|
|
|
52
|
1 |
|
return $this->io->close(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
1 |
|
public function peek($length, $blocking = true) |
59
|
|
|
{ |
60
|
1 |
|
return $this->io->peek($length, $blocking); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
1 |
|
public function read($length, $blocking = true) |
67
|
|
|
{ |
68
|
1 |
|
$data = $this->io->read($length, $blocking); |
69
|
|
|
|
70
|
1 |
|
$this->logger->debug(new ReadableBinaryData('Reading', $data)); |
71
|
|
|
|
72
|
1 |
|
return $data; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
1 |
|
public function write($data, $length = null) |
79
|
|
|
{ |
80
|
1 |
|
$this->logger->debug(new ReadableBinaryData('Writing', $data)); |
81
|
|
|
|
82
|
1 |
|
return $this->io->write($data, $length); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|