transport = $transport; $this->logger = $logger; $this->defaultTransportSettings($this->transport); } /** * @inheritdoc */ public function getTransport(): Transport { return $this->transport; } /** * @inheritdoc */ public function getLogger(): LoggerInterface { return $this->logger; } /** * Set the default settings for Elasticsearch */ protected function defaultTransportSettings(Transport $transport): void { $transport->setUserAgent('elasticsearch-php', self::VERSION); } /** * @inheritdoc */ public function setAsync(bool $async): self { $this->async = $async; return $this; } /** * @inheritdoc */ public function getAsync(): bool { return $this->async; } /** * @inheritdoc */ public function setElasticMetaHeader(bool $active): self { $this->elasticMetaHeader = $active; return $this; } /** * @inheritdoc */ public function getElasticMetaHeader(): bool { return $this->elasticMetaHeader; } /** * @inheritdoc */ public function setResponseException(bool $active): self { $this->responseException = $active; return $this; } /** * @inheritdoc */ public function getResponseException(): bool { return $this->responseException; } /** * @inheritdoc */ public function sendRequest(RequestInterface $request) { // If async returns a Promise if ($this->getAsync()) { if ($this->getElasticMetaHeader()) { $this->transport->setElasticMetaHeader(Client::CLIENT_NAME, Client::VERSION, true); } $this->transport->setAsyncOnSuccess( $request->getMethod() === 'HEAD' ? new AsyncOnSuccessNoException : ($this->getResponseException() ? new AsyncOnSuccess : new AsyncOnSuccessNoException) ); return $this->transport->sendAsyncRequest($request); } if ($this->getElasticMetaHeader()) { $this->transport->setElasticMetaHeader(Client::CLIENT_NAME, Client::VERSION, false); } $start = microtime(true); $response = $this->transport->sendRequest($request); $this->logger->info(sprintf("Response time in %.3f sec", microtime(true) - $start)); $result = new Elasticsearch; $result->setResponse($response, $request->getMethod() === 'HEAD' ? false : $this->getResponseException()); return $result; } }