Skip to content

Commit

Permalink
Move resultOrFuture from endpoint to transport
Browse files Browse the repository at this point in the history
  • Loading branch information
joelwurtz committed Jul 29, 2016
1 parent a79a772 commit 80bfeea
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 256 deletions.
102 changes: 35 additions & 67 deletions src/Elasticsearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ public function info($params = [])
/** @var \Elasticsearch\Endpoints\Info $endpoint */
$endpoint = $endpointBuilder('Info');
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

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

try {
$response = $this->performRequest($endpoint);
$endpoint->resultOrFuture($response);
$this->performRequest($endpoint);
} catch (Missing404Exception $exception) {
return false;
} catch (TransportException $exception) {
Expand Down Expand Up @@ -177,9 +175,8 @@ public function get($params)
->setIndex($index)
->setType($type);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -213,9 +210,8 @@ public function getSource($params)
->setType($type)
->returnOnlySource();
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -253,9 +249,8 @@ public function delete($params)
->setIndex($index)
->setType($type);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -289,9 +284,8 @@ public function count($params = array())
->setType($type)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -332,9 +326,8 @@ public function countPercolate($params = array())
->setID($id)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -366,9 +359,8 @@ public function percolate($params)
->setID($id)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -399,9 +391,8 @@ public function mpercolate($params = array())
->setType($type)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -439,9 +430,8 @@ public function termvectors($params = array())
->setID($id)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -478,9 +468,8 @@ public function mtermvectors($params = array())
->setType($type)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -552,9 +541,8 @@ public function mget($params = array())
->setType($type)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -582,9 +570,8 @@ public function msearch($params = array())
->setType($type)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -625,9 +612,8 @@ public function create($params)
->setBody($body)
->createIfAbsent();
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -658,9 +644,8 @@ public function bulk($params = array())
->setType($type)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -701,9 +686,8 @@ public function index($params)
->setType($type)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand All @@ -728,9 +712,8 @@ public function reindex($params)
$endpoint = $endpointBuilder('Reindex');
$endpoint->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -758,9 +741,8 @@ public function suggest($params = array())
$endpoint->setIndex($index)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -805,9 +787,8 @@ public function explain($params)
->setType($type)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -865,9 +846,8 @@ public function search($params = array())
->setType($type)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -897,9 +877,8 @@ public function searchShards($params = array())
$endpoint->setIndex($index)
->setType($type);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand All @@ -925,9 +904,8 @@ public function searchTemplate($params = array())
->setType($type)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand All @@ -952,9 +930,8 @@ public function scroll($params = array())
$endpoint->setScrollID($scrollID)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand All @@ -980,9 +957,8 @@ public function clearScroll($params = array())
->setBody($body)
->setClearScroll(true);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -1025,9 +1001,8 @@ public function update($params)
->setType($type)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand All @@ -1051,9 +1026,8 @@ public function getScript($params)
$endpoint->setID($id)
->setLang($lang);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand All @@ -1077,9 +1051,8 @@ public function deleteScript($params)
$endpoint->setID($id)
->setLang($lang);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand All @@ -1105,9 +1078,8 @@ public function putScript($params)
->setLang($lang)
->setBody($body);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

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

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

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

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand All @@ -1176,9 +1146,8 @@ public function putTemplate($params)
$endpoint->setID($id)
->setBody($body)
->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -1206,9 +1175,8 @@ public function fieldStats($params = array())
$endpoint->setIndex($index)
->setBody($body)
->setParams($params);
$response = $this->performRequest($endpoint);

return $endpoint->resultOrFuture($response);
return $this->performRequest($endpoint);
}

/**
Expand All @@ -1231,8 +1199,8 @@ public function renderSearchTemplate($params = array())
$endpoint->setBody($body)
->setID($id);
$endpoint->setParams($params);
$response = $this->performRequest($endpoint);
return $endpoint->resultOrFuture($response);

return $this->performRequest($endpoint);
}

/**
Expand Down Expand Up @@ -1378,6 +1346,6 @@ private function performRequest(AbstractEndpoint $endpoint)
$endpoint->getOptions()
);

return $promise;
return $this->transport->resultOrFuture($promise, $endpoint->getOptions());
}
}
19 changes: 0 additions & 19 deletions src/Elasticsearch/Endpoints/AbstractEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,6 @@ public function setID($docID)
return $this;
}

/**
* @param $result
* @return callable|array
*/
public function resultOrFuture($result)
{
$response = null;
$async = isset($this->options['client']['future']) ? $this->options['client']['future'] : null;
if (is_null($async) || $async === false) {
do {
$result = $result->wait();
} while ($result instanceof FutureArrayInterface);

return $result;
} elseif ($async === true || $async === 'lazy') {
return $result;
}
}

/**
* @return array
*/
Expand Down
Loading

0 comments on commit 80bfeea

Please sign in to comment.