Refactoring: Add typed Connection::command method if favor of send

This commit is contained in:
2021-01-25 01:56:58 +03:00
parent 66b5b77bef
commit 551bcfb10b
3 changed files with 24 additions and 30 deletions

View File

@@ -7,8 +7,6 @@ namespace Nsq;
use function array_map;
use function implode;
use function pack;
use function sprintf;
use const PHP_EOL;
final class Producer extends Connection
{
@@ -17,11 +15,7 @@ final class Producer extends Connection
*/
public function pub(string $topic, string $body): void
{
$size = pack('N', \strlen($body));
$buffer = 'PUB '.$topic.PHP_EOL.$size.$body;
$this->send($buffer)->response()->okOrFail();
$this->command('PUB', $topic, $body)->response()->okOrFail();
}
/**
@@ -37,11 +31,7 @@ final class Producer extends Connection
return pack('N', \strlen($body)).$body;
}, $bodies));
$size = pack('N', \strlen($num.$mb));
$buffer = 'MPUB '.$topic.PHP_EOL.$size.$num.$mb;
$this->send($buffer)->response()->okOrFail();
$this->command('MPUB', $topic, $num.$mb)->response()->okOrFail();
}
/**
@@ -49,10 +39,6 @@ final class Producer extends Connection
*/
public function dpub(string $topic, int $deferTime, string $body): void
{
$size = pack('N', \strlen($body));
$buffer = sprintf('DPUB %s %s', $topic, $deferTime).PHP_EOL.$size.$body;
$this->send($buffer)->response()->okOrFail();
$this->command('DPUB', [$topic, $deferTime], $body)->response()->okOrFail();
}
}