Skip to content

Commit

Permalink
chore: fix variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
EJTJ3 committed Jul 27, 2023
1 parent ba1178b commit 7f99682
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Connection/ClientConnectionOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct(
/**
* Turns on +OK protocol acknowledgements.
*/
private bool $verbose = true,
private bool $verbose = false,

/**
* Turns on additional strict format checking, e.g. for properly formed subjects.
Expand Down
20 changes: 16 additions & 4 deletions src/Connection/NatsConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,28 @@ public function __construct(
$this->currentServer = null;
$this->connected = false;
$this->isVerbose = false;
$this->enableNoResponder = false;
}

public function setNoResponders(bool $enabled = true): void
{
if ($this->isConnected()) {
throw new InvalidArgumentException('Stream is already connected, enable no-responders before connecting. ');
}

// Headers must be enabled for no responders.
$this->enableNoResponder = $enabled;
}

public function setVerbose(bool $verbose): void
{
if ($this->isConnected()) {
throw new InvalidArgumentException('Stream is already connected, enable verbose before connecting. ');
}

$this->isVerbose = $verbose;
}

/**
* @throws Exception
*/
Expand Down Expand Up @@ -217,16 +231,14 @@ private function doConnect(): void
$server = $this->currentServer;

$connectionOptions = new ClientConnectionOptions();
$connectionOptions->setPedantic(false);
$connectionOptions->setVerbose(false);

if ($this->enableNoResponder) {
$connectionOptions->setNoResponders(true);
$connectionOptions->setHeaders(true);
}

if ($connectionOptions->isVerbose() === true) {
$this->isVerbose = true;
if ($this->isVerbose === true) {
$connectionOptions->setVerbose(true);
}

if (!StringUtil::isEmpty($server->getUser()) && !StringUtil::isEmpty($server->getPassword())) {
Expand Down
8 changes: 4 additions & 4 deletions src/Connection/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public static function parse(string $payload): NatsResponseInterface
return new Pong();
}

if (NatsProtocolOperation::Ping->isOperation($payload)) {
return new Ping();
}

if (NatsProtocolOperation::Ack->isOperation($payload)) {
return new Acknowledgement();
}
Expand All @@ -38,14 +42,10 @@ public static function parse(string $payload): NatsResponseInterface
throw new RuntimeException('Operation is not supported');
}

dump($operation);

return match ($operation) {
NatsProtocolOperation::HEADER_MSG => HMsg::create($body),
NatsProtocolOperation::Msg => Msg::create($body),
NatsProtocolOperation::Info => \EJTJ3\PhpNats\Connection\ServerInfo::fromData($body),
NatsProtocolOperation::Ping => new Ping(),
NatsProtocolOperation::Pong => new Pong(),
default => throw new LogicException('Not implemented yet')
};
}
Expand Down

0 comments on commit 7f99682

Please sign in to comment.