Skip to content

Added a ClientInterface #1249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface;

final class Client
final class Client implements ClientInterface
{
const CLIENT_NAME = 'es';
const VERSION = '8.4.0';
Expand Down Expand Up @@ -68,11 +68,17 @@ public function __construct(
$this->defaultTransportSettings($this->transport);
}

/**
* @inheritdoc
*/
public function getTransport(): Transport
{
return $this->transport;
}

/**
* @inheritdoc
*/
public function getLogger(): LoggerInterface
{
return $this->logger;
Expand All @@ -87,7 +93,7 @@ protected function defaultTransportSettings(Transport $transport): void
}

/**
* Set the asyncronous HTTP request
* @inheritdoc
*/
public function setAsync(bool $async): self
{
Expand All @@ -96,15 +102,15 @@ public function setAsync(bool $async): self
}

/**
* Get the asyncronous HTTP request setting
* @inheritdoc
*/
public function getAsync(): bool
{
return $this->async;
}

/**
* Enable or disable the x-elastic-client-meta header
* @inheritdoc
*/
public function setElasticMetaHeader(bool $active): self
{
Expand All @@ -113,15 +119,15 @@ public function setElasticMetaHeader(bool $active): self
}

/**
* Get the status of x-elastic-client-meta header
* @inheritdoc
*/
public function getElasticMetaHeader(): bool
{
return $this->elasticMetaHeader;
}

/**
* Enable or disable the response Exception
* @inheritdoc
*/
public function setResponseException(bool $active): self
{
Expand All @@ -130,18 +136,15 @@ public function setResponseException(bool $active): self
}

/**
* Get the status of response Exception
* @inheritdoc
*/
public function getResponseException(): bool
{
return $this->responseException;
}

/**
* Send the HTTP request using the Elastic Transport.
* It manages syncronous and asyncronus requests using Client::getAsync()
*
* @return Elasticsearch|Promise
* @inheritdoc
*/
public function sendRequest(RequestInterface $request)
{
Expand Down
72 changes: 72 additions & 0 deletions src/ClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Elasticsearch PHP Client
*
* @link https://github.com/elastic/elasticsearch-php
* @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co)
* @license https://opensource.org/licenses/MIT MIT License
*
* Licensed to Elasticsearch B.V under one or more agreements.
* Elasticsearch B.V licenses this file to you under the MIT License.
* See the LICENSE file in the project root for more information.
*/
declare(strict_types = 1);

namespace Elastic\Elasticsearch;

use Elastic\Elasticsearch\Response\Elasticsearch;
use Elastic\Transport\Transport;
use Http\Promise\Promise;
use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface;

interface ClientInterface
{
/**
* Get the Elastic\Transport\Transport
*/
public function getTransport(): Transport;

/**
* Get the PSR-3 logger
*/
public function getLogger(): LoggerInterface;

/**
* Set the asyncronous HTTP request
*/
public function setAsync(bool $async): self;

/**
* Get the asyncronous HTTP request setting
*/
public function getAsync(): bool;

/**
* Enable or disable the x-elastic-client-meta header
*/
public function setElasticMetaHeader(bool $active): self;

/**
* Get the status of x-elastic-client-meta header
*/
public function getElasticMetaHeader(): bool;

/**
* Enable or disable the response Exception
*/
public function setResponseException(bool $active): self;

/**
* Get the status of response Exception
*/
public function getResponseException(): bool;

/**
* Send the HTTP request using the Elastic Transport.
* It manages syncronous and asyncronus requests using Client::getAsync()
*
* @return Elasticsearch|Promise
*/
public function sendRequest(RequestInterface $request);
}
6 changes: 3 additions & 3 deletions src/Endpoints/AbstractEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

namespace Elastic\Elasticsearch\Endpoints;

use Elastic\Elasticsearch\Client;
use Elastic\Elasticsearch\ClientInterface;
use Elastic\Elasticsearch\Traits\EndpointTrait;

abstract class AbstractEndpoint
{
use EndpointTrait;

protected Client $client;
protected ClientInterface $client;

public function __construct(Client $client)
public function __construct(ClientInterface $client)
{
$this->client = $client;
}
Expand Down