Skip to content

Commit eba27a8

Browse files
authored
Added a ClientInterface (#1249)
* Added a ClientInterface * Moved phpdoc in ClientInterface
1 parent 182bb10 commit eba27a8

File tree

3 files changed

+89
-14
lines changed

3 files changed

+89
-14
lines changed

src/Client.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
use Psr\Http\Message\RequestInterface;
2626
use Psr\Log\LoggerInterface;
2727

28-
final class Client
28+
final class Client implements ClientInterface
2929
{
3030
const CLIENT_NAME = 'es';
3131
const VERSION = '8.4.0';
@@ -68,11 +68,17 @@ public function __construct(
6868
$this->defaultTransportSettings($this->transport);
6969
}
7070

71+
/**
72+
* @inheritdoc
73+
*/
7174
public function getTransport(): Transport
7275
{
7376
return $this->transport;
7477
}
7578

79+
/**
80+
* @inheritdoc
81+
*/
7682
public function getLogger(): LoggerInterface
7783
{
7884
return $this->logger;
@@ -87,7 +93,7 @@ protected function defaultTransportSettings(Transport $transport): void
8793
}
8894

8995
/**
90-
* Set the asyncronous HTTP request
96+
* @inheritdoc
9197
*/
9298
public function setAsync(bool $async): self
9399
{
@@ -96,15 +102,15 @@ public function setAsync(bool $async): self
96102
}
97103

98104
/**
99-
* Get the asyncronous HTTP request setting
105+
* @inheritdoc
100106
*/
101107
public function getAsync(): bool
102108
{
103109
return $this->async;
104110
}
105111

106112
/**
107-
* Enable or disable the x-elastic-client-meta header
113+
* @inheritdoc
108114
*/
109115
public function setElasticMetaHeader(bool $active): self
110116
{
@@ -113,15 +119,15 @@ public function setElasticMetaHeader(bool $active): self
113119
}
114120

115121
/**
116-
* Get the status of x-elastic-client-meta header
122+
* @inheritdoc
117123
*/
118124
public function getElasticMetaHeader(): bool
119125
{
120126
return $this->elasticMetaHeader;
121127
}
122128

123129
/**
124-
* Enable or disable the response Exception
130+
* @inheritdoc
125131
*/
126132
public function setResponseException(bool $active): self
127133
{
@@ -130,18 +136,15 @@ public function setResponseException(bool $active): self
130136
}
131137

132138
/**
133-
* Get the status of response Exception
139+
* @inheritdoc
134140
*/
135141
public function getResponseException(): bool
136142
{
137143
return $this->responseException;
138144
}
139145

140146
/**
141-
* Send the HTTP request using the Elastic Transport.
142-
* It manages syncronous and asyncronus requests using Client::getAsync()
143-
*
144-
* @return Elasticsearch|Promise
147+
* @inheritdoc
145148
*/
146149
public function sendRequest(RequestInterface $request)
147150
{

src/ClientInterface.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Elasticsearch PHP Client
4+
*
5+
* @link https://github.com/elastic/elasticsearch-php
6+
* @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co)
7+
* @license https://opensource.org/licenses/MIT MIT License
8+
*
9+
* Licensed to Elasticsearch B.V under one or more agreements.
10+
* Elasticsearch B.V licenses this file to you under the MIT License.
11+
* See the LICENSE file in the project root for more information.
12+
*/
13+
declare(strict_types = 1);
14+
15+
namespace Elastic\Elasticsearch;
16+
17+
use Elastic\Elasticsearch\Response\Elasticsearch;
18+
use Elastic\Transport\Transport;
19+
use Http\Promise\Promise;
20+
use Psr\Http\Message\RequestInterface;
21+
use Psr\Log\LoggerInterface;
22+
23+
interface ClientInterface
24+
{
25+
/**
26+
* Get the Elastic\Transport\Transport
27+
*/
28+
public function getTransport(): Transport;
29+
30+
/**
31+
* Get the PSR-3 logger
32+
*/
33+
public function getLogger(): LoggerInterface;
34+
35+
/**
36+
* Set the asyncronous HTTP request
37+
*/
38+
public function setAsync(bool $async): self;
39+
40+
/**
41+
* Get the asyncronous HTTP request setting
42+
*/
43+
public function getAsync(): bool;
44+
45+
/**
46+
* Enable or disable the x-elastic-client-meta header
47+
*/
48+
public function setElasticMetaHeader(bool $active): self;
49+
50+
/**
51+
* Get the status of x-elastic-client-meta header
52+
*/
53+
public function getElasticMetaHeader(): bool;
54+
55+
/**
56+
* Enable or disable the response Exception
57+
*/
58+
public function setResponseException(bool $active): self;
59+
60+
/**
61+
* Get the status of response Exception
62+
*/
63+
public function getResponseException(): bool;
64+
65+
/**
66+
* Send the HTTP request using the Elastic Transport.
67+
* It manages syncronous and asyncronus requests using Client::getAsync()
68+
*
69+
* @return Elasticsearch|Promise
70+
*/
71+
public function sendRequest(RequestInterface $request);
72+
}

src/Endpoints/AbstractEndpoint.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414

1515
namespace Elastic\Elasticsearch\Endpoints;
1616

17-
use Elastic\Elasticsearch\Client;
17+
use Elastic\Elasticsearch\ClientInterface;
1818
use Elastic\Elasticsearch\Traits\EndpointTrait;
1919

2020
abstract class AbstractEndpoint
2121
{
2222
use EndpointTrait;
2323

24-
protected Client $client;
24+
protected ClientInterface $client;
2525

26-
public function __construct(Client $client)
26+
public function __construct(ClientInterface $client)
2727
{
2828
$this->client = $client;
2929
}

0 commit comments

Comments
 (0)