Skip to content

Commit ecd454c

Browse files
committed
[Internal BWC Break] Refactor to remove Transport dependence in endpoints
This removes the reliance on Transport inside of endpoints. Instead of endpoints calling transport->performRequest(), the endpoint is used as a temporary object that performs validation and input manipulation. The Namespace then uses this object to invoke transport->performRequest() directly. This will make injecting custom namespaces significantly easier, since it makes the dependency graph easier to wire. It also makes mocking / unit tests easier. Related to #421
1 parent 38c05da commit ecd454c

File tree

137 files changed

+590
-585
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+590
-585
lines changed

src/Elasticsearch/Client.php

Lines changed: 60 additions & 67 deletions
Large diffs are not rendered by default.

src/Elasticsearch/ClientBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,12 @@ public function build()
430430
$transport = $this->transport;
431431
$serializer = $this->serializer;
432432

433-
$this->endpoint = function ($class) use ($transport, $serializer) {
433+
$this->endpoint = function ($class) use ($serializer) {
434434
$fullPath = '\\Elasticsearch\\Endpoints\\' . $class;
435435
if ($class === 'Bulk' || $class === 'Msearch' || $class === 'MPercolate') {
436-
return new $fullPath($transport, $serializer);
436+
return new $fullPath($serializer);
437437
} else {
438-
return new $fullPath($transport);
438+
return new $fullPath();
439439
}
440440
};
441441
}

src/Elasticsearch/Endpoints/AbstractEndpoint.php

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Elasticsearch\Endpoints;
44

55
use Elasticsearch\Common\Exceptions\UnexpectedValueException;
6+
use Elasticsearch\Serializers\SerializerInterface;
67
use Elasticsearch\Transport;
78
use Exception;
89
use GuzzleHttp\Ring\Future\FutureArrayInterface;
@@ -36,51 +37,27 @@ abstract class AbstractEndpoint
3637
/** @var array */
3738
protected $body = null;
3839

39-
/** @var \Elasticsearch\Transport */
40-
private $transport = null;
41-
4240
/** @var array */
4341
private $options = [];
4442

43+
/** @var SerializerInterface */
44+
protected $serializer;
45+
4546
/**
4647
* @return string[]
4748
*/
48-
abstract protected function getParamWhitelist();
49+
abstract public function getParamWhitelist();
4950

5051
/**
5152
* @return string
5253
*/
53-
abstract protected function getURI();
54+
abstract public function getURI();
5455

5556
/**
5657
* @return string
5758
*/
58-
abstract protected function getMethod();
59-
60-
/**
61-
* @param Transport $transport
62-
*/
63-
public function __construct($transport)
64-
{
65-
$this->transport = $transport;
66-
}
59+
abstract public function getMethod();
6760

68-
/**
69-
* @throws \Exception
70-
* @return array
71-
*/
72-
public function performRequest()
73-
{
74-
$promise = $this->transport->performRequest(
75-
$this->getMethod(),
76-
$this->getURI(),
77-
$this->params,
78-
$this->getBody(),
79-
$this->options
80-
);
81-
82-
return $promise;
83-
}
8461

8562
/**
8663
* Set the parameters for this endpoint
@@ -102,6 +79,22 @@ public function setParams($params)
10279
return $this;
10380
}
10481

82+
/**
83+
* @return array
84+
*/
85+
public function getParams()
86+
{
87+
return $this->params;
88+
}
89+
90+
/**
91+
* @return array
92+
*/
93+
public function getOptions()
94+
{
95+
return $this->options;
96+
}
97+
10598
/**
10699
* @param string $index
107100
*
@@ -182,7 +175,7 @@ public function resultOrFuture($result)
182175
/**
183176
* @return array
184177
*/
185-
protected function getBody()
178+
public function getBody()
186179
{
187180
return $this->body;
188181
}

src/Elasticsearch/Endpoints/Bulk.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
class Bulk extends AbstractEndpoint implements BulkEndpointInterface
1818
{
1919
/**
20-
* @param Transport $transport
2120
* @param SerializerInterface $serializer
2221
*/
23-
public function __construct(Transport $transport, SerializerInterface $serializer)
22+
public function __construct(SerializerInterface $serializer)
2423
{
2524
$this->serializer = $serializer;
26-
parent::__construct($transport);
2725
}
2826

2927
/**
@@ -51,15 +49,15 @@ public function setBody($body)
5149
/**
5250
* @return string
5351
*/
54-
protected function getURI()
52+
public function getURI()
5553
{
5654
return $this->getOptionalURI('_bulk');
5755
}
5856

5957
/**
6058
* @return string[]
6159
*/
62-
protected function getParamWhitelist()
60+
public function getParamWhitelist()
6361
{
6462
return array(
6563
'consistency',
@@ -74,7 +72,7 @@ protected function getParamWhitelist()
7472
/**
7573
* @return string
7674
*/
77-
protected function getMethod()
75+
public function getMethod()
7876
{
7977
return 'POST';
8078
}

src/Elasticsearch/Endpoints/BulkEndpointInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ interface BulkEndpointInterface
1919
/**
2020
* Constructor
2121
*
22-
* @param Transport $transport Transport instance
2322
* @param SerializerInterface $serializer A serializer
2423
*/
25-
public function __construct(Transport $transport, SerializerInterface $serializer);
24+
public function __construct(SerializerInterface $serializer);
2625
}

src/Elasticsearch/Endpoints/Cat/Aliases.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function setName($name)
3737
/**
3838
* @return string
3939
*/
40-
protected function getURI()
40+
public function getURI()
4141
{
4242
$name = $this->name;
4343
$uri = "/_cat/aliases";
@@ -52,7 +52,7 @@ protected function getURI()
5252
/**
5353
* @return string[]
5454
*/
55-
protected function getParamWhitelist()
55+
public function getParamWhitelist()
5656
{
5757
return array(
5858
'local',
@@ -67,7 +67,7 @@ protected function getParamWhitelist()
6767
/**
6868
* @return string
6969
*/
70-
protected function getMethod()
70+
public function getMethod()
7171
{
7272
return 'GET';
7373
}

src/Elasticsearch/Endpoints/Cat/Allocation.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function setNodeId($node_id)
3737
/**
3838
* @return string
3939
*/
40-
protected function getURI()
40+
public function getURI()
4141
{
4242
$node_id = $this->node_id;
4343
$uri = "/_cat/allocation";
@@ -52,7 +52,7 @@ protected function getURI()
5252
/**
5353
* @return string[]
5454
*/
55-
protected function getParamWhitelist()
55+
public function getParamWhitelist()
5656
{
5757
return array(
5858
'bytes',
@@ -67,7 +67,7 @@ protected function getParamWhitelist()
6767
/**
6868
* @return string
6969
*/
70-
protected function getMethod()
70+
public function getMethod()
7171
{
7272
return 'GET';
7373
}

src/Elasticsearch/Endpoints/Cat/Count.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Count extends AbstractEndpoint
1818
/**
1919
* @return string
2020
*/
21-
protected function getURI()
21+
public function getURI()
2222
{
2323
$index = $this->index;
2424
$uri = "/_cat/count";
@@ -33,7 +33,7 @@ protected function getURI()
3333
/**
3434
* @return string[]
3535
*/
36-
protected function getParamWhitelist()
36+
public function getParamWhitelist()
3737
{
3838
return array(
3939
'local',
@@ -47,7 +47,7 @@ protected function getParamWhitelist()
4747
/**
4848
* @return string
4949
*/
50-
protected function getMethod()
50+
public function getMethod()
5151
{
5252
return 'GET';
5353
}

src/Elasticsearch/Endpoints/Cat/Fielddata.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function setFields($fields)
3636
/**
3737
* @return string
3838
*/
39-
protected function getURI()
39+
public function getURI()
4040
{
4141
$fields = $this->fields;
4242
$uri = "/_cat/fielddata";
@@ -51,7 +51,7 @@ protected function getURI()
5151
/**
5252
* @return string[]
5353
*/
54-
protected function getParamWhitelist()
54+
public function getParamWhitelist()
5555
{
5656
return array(
5757
'local',
@@ -65,7 +65,7 @@ protected function getParamWhitelist()
6565
/**
6666
* @return string
6767
*/
68-
protected function getMethod()
68+
public function getMethod()
6969
{
7070
return 'GET';
7171
}

src/Elasticsearch/Endpoints/Cat/Health.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Health extends AbstractEndpoint
1818
/**
1919
* @return string
2020
*/
21-
protected function getURI()
21+
public function getURI()
2222
{
2323
$uri = "/_cat/health";
2424

@@ -28,7 +28,7 @@ protected function getURI()
2828
/**
2929
* @return string[]
3030
*/
31-
protected function getParamWhitelist()
31+
public function getParamWhitelist()
3232
{
3333
return array(
3434
'local',
@@ -43,7 +43,7 @@ protected function getParamWhitelist()
4343
/**
4444
* @return string
4545
*/
46-
protected function getMethod()
46+
public function getMethod()
4747
{
4848
return 'GET';
4949
}

0 commit comments

Comments
 (0)