generated from Nodarx/template
feat: initial version
Signed-off-by: Sebastian Krupinski <root@LAPTOP-7DVOR6NC>
This commit is contained in:
55
lib/Client/Transport/Traceable/TraceableConnection.php
Normal file
55
lib/Client/Transport/Traceable/TraceableConnection.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Gricob\IMAP\Transport\Traceable;
|
||||
|
||||
use Gricob\IMAP\Transport\Connection;
|
||||
use Gricob\IMAP\Transport\ResponseStream;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
final readonly class TraceableConnection implements Connection
|
||||
{
|
||||
public function __construct(
|
||||
private Connection $connection,
|
||||
private LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
public function isOpen(): bool
|
||||
{
|
||||
return $this->connection->isOpen();
|
||||
}
|
||||
|
||||
public function open(): void
|
||||
{
|
||||
$this->connection->open();
|
||||
}
|
||||
|
||||
public function close(): void
|
||||
{
|
||||
$this->connection->close();
|
||||
}
|
||||
|
||||
public function send(string $data): void
|
||||
{
|
||||
$this->debug(addslashes($data));
|
||||
|
||||
$this->connection->send($data);
|
||||
}
|
||||
|
||||
public function receive(): ResponseStream
|
||||
{
|
||||
return new TraceableResponseStream(
|
||||
$this->connection->receive(),
|
||||
$this->logger,
|
||||
);
|
||||
}
|
||||
|
||||
private function debug(string $data): void
|
||||
{
|
||||
$data = str_replace("\r\n", "\\r\\n", $data);
|
||||
|
||||
$this->logger->debug($data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user