Skip to content

Commit 80bfeea

Browse files
committed
Move resultOrFuture from endpoint to transport
1 parent a79a772 commit 80bfeea

12 files changed

+147
-256
lines changed

src/Elasticsearch/Client.php

Lines changed: 35 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ public function info($params = [])
112112
/** @var \Elasticsearch\Endpoints\Info $endpoint */
113113
$endpoint = $endpointBuilder('Info');
114114
$endpoint->setParams($params);
115-
$response = $this->performRequest($endpoint);
116115

117-
return $endpoint->resultOrFuture($response);
116+
return $this->performRequest($endpoint);
118117
}
119118

120119
/**
@@ -132,8 +131,7 @@ public function ping($params = [])
132131
$endpoint->setParams($params);
133132

134133
try {
135-
$response = $this->performRequest($endpoint);
136-
$endpoint->resultOrFuture($response);
134+
$this->performRequest($endpoint);
137135
} catch (Missing404Exception $exception) {
138136
return false;
139137
} catch (TransportException $exception) {
@@ -177,9 +175,8 @@ public function get($params)
177175
->setIndex($index)
178176
->setType($type);
179177
$endpoint->setParams($params);
180-
$response = $this->performRequest($endpoint);
181178

182-
return $endpoint->resultOrFuture($response);
179+
return $this->performRequest($endpoint);
183180
}
184181

185182
/**
@@ -213,9 +210,8 @@ public function getSource($params)
213210
->setType($type)
214211
->returnOnlySource();
215212
$endpoint->setParams($params);
216-
$response = $this->performRequest($endpoint);
217213

218-
return $endpoint->resultOrFuture($response);
214+
return $this->performRequest($endpoint);
219215
}
220216

221217
/**
@@ -253,9 +249,8 @@ public function delete($params)
253249
->setIndex($index)
254250
->setType($type);
255251
$endpoint->setParams($params);
256-
$response = $this->performRequest($endpoint);
257252

258-
return $endpoint->resultOrFuture($response);
253+
return $this->performRequest($endpoint);
259254
}
260255

261256
/**
@@ -289,9 +284,8 @@ public function count($params = array())
289284
->setType($type)
290285
->setBody($body);
291286
$endpoint->setParams($params);
292-
$response = $this->performRequest($endpoint);
293287

294-
return $endpoint->resultOrFuture($response);
288+
return $this->performRequest($endpoint);
295289
}
296290

297291
/**
@@ -332,9 +326,8 @@ public function countPercolate($params = array())
332326
->setID($id)
333327
->setBody($body);
334328
$endpoint->setParams($params);
335-
$response = $this->performRequest($endpoint);
336329

337-
return $endpoint->resultOrFuture($response);
330+
return $this->performRequest($endpoint);
338331
}
339332

340333
/**
@@ -366,9 +359,8 @@ public function percolate($params)
366359
->setID($id)
367360
->setBody($body);
368361
$endpoint->setParams($params);
369-
$response = $this->performRequest($endpoint);
370362

371-
return $endpoint->resultOrFuture($response);
363+
return $this->performRequest($endpoint);
372364
}
373365

374366
/**
@@ -399,9 +391,8 @@ public function mpercolate($params = array())
399391
->setType($type)
400392
->setBody($body);
401393
$endpoint->setParams($params);
402-
$response = $this->performRequest($endpoint);
403394

404-
return $endpoint->resultOrFuture($response);
395+
return $this->performRequest($endpoint);
405396
}
406397

407398
/**
@@ -439,9 +430,8 @@ public function termvectors($params = array())
439430
->setID($id)
440431
->setBody($body);
441432
$endpoint->setParams($params);
442-
$response = $this->performRequest($endpoint);
443433

444-
return $endpoint->resultOrFuture($response);
434+
return $this->performRequest($endpoint);
445435
}
446436

447437
/**
@@ -478,9 +468,8 @@ public function mtermvectors($params = array())
478468
->setType($type)
479469
->setBody($body);
480470
$endpoint->setParams($params);
481-
$response = $this->performRequest($endpoint);
482471

483-
return $endpoint->resultOrFuture($response);
472+
return $this->performRequest($endpoint);
484473
}
485474

486475
/**
@@ -552,9 +541,8 @@ public function mget($params = array())
552541
->setType($type)
553542
->setBody($body);
554543
$endpoint->setParams($params);
555-
$response = $this->performRequest($endpoint);
556544

557-
return $endpoint->resultOrFuture($response);
545+
return $this->performRequest($endpoint);
558546
}
559547

560548
/**
@@ -582,9 +570,8 @@ public function msearch($params = array())
582570
->setType($type)
583571
->setBody($body);
584572
$endpoint->setParams($params);
585-
$response = $this->performRequest($endpoint);
586573

587-
return $endpoint->resultOrFuture($response);
574+
return $this->performRequest($endpoint);
588575
}
589576

590577
/**
@@ -625,9 +612,8 @@ public function create($params)
625612
->setBody($body)
626613
->createIfAbsent();
627614
$endpoint->setParams($params);
628-
$response = $this->performRequest($endpoint);
629615

630-
return $endpoint->resultOrFuture($response);
616+
return $this->performRequest($endpoint);
631617
}
632618

633619
/**
@@ -658,9 +644,8 @@ public function bulk($params = array())
658644
->setType($type)
659645
->setBody($body);
660646
$endpoint->setParams($params);
661-
$response = $this->performRequest($endpoint);
662647

663-
return $endpoint->resultOrFuture($response);
648+
return $this->performRequest($endpoint);
664649
}
665650

666651
/**
@@ -701,9 +686,8 @@ public function index($params)
701686
->setType($type)
702687
->setBody($body);
703688
$endpoint->setParams($params);
704-
$response = $this->performRequest($endpoint);
705689

706-
return $endpoint->resultOrFuture($response);
690+
return $this->performRequest($endpoint);
707691
}
708692

709693
/**
@@ -728,9 +712,8 @@ public function reindex($params)
728712
$endpoint = $endpointBuilder('Reindex');
729713
$endpoint->setBody($body);
730714
$endpoint->setParams($params);
731-
$response = $this->performRequest($endpoint);
732715

733-
return $endpoint->resultOrFuture($response);
716+
return $this->performRequest($endpoint);
734717
}
735718

736719
/**
@@ -758,9 +741,8 @@ public function suggest($params = array())
758741
$endpoint->setIndex($index)
759742
->setBody($body);
760743
$endpoint->setParams($params);
761-
$response = $this->performRequest($endpoint);
762744

763-
return $endpoint->resultOrFuture($response);
745+
return $this->performRequest($endpoint);
764746
}
765747

766748
/**
@@ -805,9 +787,8 @@ public function explain($params)
805787
->setType($type)
806788
->setBody($body);
807789
$endpoint->setParams($params);
808-
$response = $this->performRequest($endpoint);
809790

810-
return $endpoint->resultOrFuture($response);
791+
return $this->performRequest($endpoint);
811792
}
812793

813794
/**
@@ -865,9 +846,8 @@ public function search($params = array())
865846
->setType($type)
866847
->setBody($body);
867848
$endpoint->setParams($params);
868-
$response = $this->performRequest($endpoint);
869849

870-
return $endpoint->resultOrFuture($response);
850+
return $this->performRequest($endpoint);
871851
}
872852

873853
/**
@@ -897,9 +877,8 @@ public function searchShards($params = array())
897877
$endpoint->setIndex($index)
898878
->setType($type);
899879
$endpoint->setParams($params);
900-
$response = $this->performRequest($endpoint);
901880

902-
return $endpoint->resultOrFuture($response);
881+
return $this->performRequest($endpoint);
903882
}
904883

905884
/**
@@ -925,9 +904,8 @@ public function searchTemplate($params = array())
925904
->setType($type)
926905
->setBody($body);
927906
$endpoint->setParams($params);
928-
$response = $this->performRequest($endpoint);
929907

930-
return $endpoint->resultOrFuture($response);
908+
return $this->performRequest($endpoint);
931909
}
932910

933911
/**
@@ -952,9 +930,8 @@ public function scroll($params = array())
952930
$endpoint->setScrollID($scrollID)
953931
->setBody($body);
954932
$endpoint->setParams($params);
955-
$response = $this->performRequest($endpoint);
956933

957-
return $endpoint->resultOrFuture($response);
934+
return $this->performRequest($endpoint);
958935
}
959936

960937
/**
@@ -980,9 +957,8 @@ public function clearScroll($params = array())
980957
->setBody($body)
981958
->setClearScroll(true);
982959
$endpoint->setParams($params);
983-
$response = $this->performRequest($endpoint);
984960

985-
return $endpoint->resultOrFuture($response);
961+
return $this->performRequest($endpoint);
986962
}
987963

988964
/**
@@ -1025,9 +1001,8 @@ public function update($params)
10251001
->setType($type)
10261002
->setBody($body);
10271003
$endpoint->setParams($params);
1028-
$response = $this->performRequest($endpoint);
10291004

1030-
return $endpoint->resultOrFuture($response);
1005+
return $this->performRequest($endpoint);
10311006
}
10321007

10331008
/**
@@ -1051,9 +1026,8 @@ public function getScript($params)
10511026
$endpoint->setID($id)
10521027
->setLang($lang);
10531028
$endpoint->setParams($params);
1054-
$response = $this->performRequest($endpoint);
10551029

1056-
return $endpoint->resultOrFuture($response);
1030+
return $this->performRequest($endpoint);
10571031
}
10581032

10591033
/**
@@ -1077,9 +1051,8 @@ public function deleteScript($params)
10771051
$endpoint->setID($id)
10781052
->setLang($lang);
10791053
$endpoint->setParams($params);
1080-
$response = $this->performRequest($endpoint);
10811054

1082-
return $endpoint->resultOrFuture($response);
1055+
return $this->performRequest($endpoint);
10831056
}
10841057

10851058
/**
@@ -1105,9 +1078,8 @@ public function putScript($params)
11051078
->setLang($lang)
11061079
->setBody($body);
11071080
$endpoint->setParams($params);
1108-
$response = $this->performRequest($endpoint);
11091081

1110-
return $endpoint->resultOrFuture($response);
1082+
return $this->performRequest($endpoint);
11111083
}
11121084

11131085
/**
@@ -1128,9 +1100,8 @@ public function getTemplate($params)
11281100
$endpoint = $endpointBuilder('Template\Get');
11291101
$endpoint->setID($id);
11301102
$endpoint->setParams($params);
1131-
$response = $this->performRequest($endpoint);
11321103

1133-
return $endpoint->resultOrFuture($response);
1104+
return $this->performRequest($endpoint);
11341105
}
11351106

11361107
/**
@@ -1151,9 +1122,8 @@ public function deleteTemplate($params)
11511122
$endpoint = $endpointBuilder('Template\Delete');
11521123
$endpoint->setID($id);
11531124
$endpoint->setParams($params);
1154-
$response = $this->performRequest($endpoint);
11551125

1156-
return $endpoint->resultOrFuture($response);
1126+
return $this->performRequest($endpoint);
11571127
}
11581128

11591129
/**
@@ -1176,9 +1146,8 @@ public function putTemplate($params)
11761146
$endpoint->setID($id)
11771147
->setBody($body)
11781148
->setParams($params);
1179-
$response = $this->performRequest($endpoint);
11801149

1181-
return $endpoint->resultOrFuture($response);
1150+
return $this->performRequest($endpoint);
11821151
}
11831152

11841153
/**
@@ -1206,9 +1175,8 @@ public function fieldStats($params = array())
12061175
$endpoint->setIndex($index)
12071176
->setBody($body)
12081177
->setParams($params);
1209-
$response = $this->performRequest($endpoint);
12101178

1211-
return $endpoint->resultOrFuture($response);
1179+
return $this->performRequest($endpoint);
12121180
}
12131181

12141182
/**
@@ -1231,8 +1199,8 @@ public function renderSearchTemplate($params = array())
12311199
$endpoint->setBody($body)
12321200
->setID($id);
12331201
$endpoint->setParams($params);
1234-
$response = $this->performRequest($endpoint);
1235-
return $endpoint->resultOrFuture($response);
1202+
1203+
return $this->performRequest($endpoint);
12361204
}
12371205

12381206
/**
@@ -1378,6 +1346,6 @@ private function performRequest(AbstractEndpoint $endpoint)
13781346
$endpoint->getOptions()
13791347
);
13801348

1381-
return $promise;
1349+
return $this->transport->resultOrFuture($promise, $endpoint->getOptions());
13821350
}
13831351
}

src/Elasticsearch/Endpoints/AbstractEndpoint.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -153,25 +153,6 @@ public function setID($docID)
153153
return $this;
154154
}
155155

156-
/**
157-
* @param $result
158-
* @return callable|array
159-
*/
160-
public function resultOrFuture($result)
161-
{
162-
$response = null;
163-
$async = isset($this->options['client']['future']) ? $this->options['client']['future'] : null;
164-
if (is_null($async) || $async === false) {
165-
do {
166-
$result = $result->wait();
167-
} while ($result instanceof FutureArrayInterface);
168-
169-
return $result;
170-
} elseif ($async === true || $async === 'lazy') {
171-
return $result;
172-
}
173-
}
174-
175156
/**
176157
* @return array
177158
*/

0 commit comments

Comments
 (0)