diff options
author | Valentin V / vvval <[email protected]> | 2020-05-04 15:35:58 +0300 |
---|---|---|
committer | Valentin V / vvval <[email protected]> | 2020-05-04 15:35:58 +0300 |
commit | bd655985a688c77cb2be96a83b3a26e1ebd983f1 (patch) | |
tree | e8f27ec7b1d26c2e2087a37492d68382c5f4cc7b | |
parent | fee8dbb4a6723068050c3396c61180a0733cf988 (diff) |
#316 Add non-optimized relays support
-rw-r--r-- | src/Worker.php | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/Worker.php b/src/Worker.php index d9de0fa9..3d1888e3 100644 --- a/src/Worker.php +++ b/src/Worker.php @@ -31,12 +31,16 @@ class Worker /** @var Relay */ private $relay; + /** @var bool */ + private $optimizedRelay; + /** * @param Relay $relay */ public function __construct(Relay $relay) { $this->relay = $relay; + $this->optimizedRelay = method_exists($relay, 'sendPackage'); } /** @@ -83,12 +87,22 @@ class Worker */ public function send(string $payload = null, string $header = null): void { - $this->relay->sendPackage( - (string)$header, - Relay::PAYLOAD_CONTROL | ($header === null ? Relay::PAYLOAD_NONE : Relay::PAYLOAD_RAW), - (string)$payload, - Relay::PAYLOAD_RAW - ); + if (!$this->optimizedRelay) { + if ($header === null) { + $this->relay->send('', Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_NONE); + } else { + $this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW); + } + + $this->relay->send((string)$payload, Relay::PAYLOAD_RAW); + } else { + $this->relay->sendPackage( + (string)$header, + Relay::PAYLOAD_CONTROL | ($header === null ? Relay::PAYLOAD_NONE : Relay::PAYLOAD_RAW), + (string)$payload, + Relay::PAYLOAD_RAW + ); + } } /** |