featureNegotiation = true; // Always enabled if ('' === $this->hostname) { $this->hostname = (static fn (mixed $h): string => \is_string($h) ? $h : '')(gethostname()); } if ('' === $this->userAgent) { $this->userAgent = 'nsqphp/'.InstalledVersions::getPrettyVersion('nsq/nsq'); } if ($this->snappy && $this->deflate) { throw new \InvalidArgumentException('Client cannot enable both [snappy] and [deflate]'); } } public static function fromArray(array $array): self { return new self(...array_intersect_key($array, get_class_vars(self::class))); } public function asNegotiationPayload(): string { $data = [ 'client_id' => $this->clientId, 'deflate' => $this->deflate, 'deflate_level' => $this->deflateLevel, 'feature_negotiation' => $this->featureNegotiation, 'heartbeat_interval' => $this->heartbeatInterval, 'hostname' => $this->hostname, 'msg_timeout' => $this->msgTimeout, 'sample_rate' => $this->sampleRate, 'snappy' => $this->snappy, 'tls_v1' => $this->tls, 'user_agent' => $this->userAgent, ]; return json_encode($data, JSON_THROW_ON_ERROR); } }