BooleanRequestWrapper.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Elasticsearch\Namespaces;
  3. use Elasticsearch\Common\Exceptions\Missing404Exception;
  4. use Elasticsearch\Common\Exceptions\RoutingMissingException;
  5. use Elasticsearch\Endpoints\AbstractEndpoint;
  6. use Elasticsearch\Transport;
  7. use GuzzleHttp\Ring\Future\FutureArrayInterface;
  8. /**
  9. * Trait AbstractNamespace
  10. *
  11. * @category Elasticsearch
  12. * @package Elasticsearch\Namespaces
  13. * @author Zachary Tong <zach@elastic.co>
  14. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
  15. * @link http://elastic.co
  16. */
  17. trait BooleanRequestWrapper
  18. {
  19. /**
  20. * Perform Request
  21. *
  22. * @param AbstractEndpoint $endpoint The Endpoint to perform this request against
  23. *
  24. * @throws Missing404Exception
  25. * @throws RoutingMissingException
  26. */
  27. public static function performRequest(AbstractEndpoint $endpoint, Transport $transport)
  28. {
  29. try {
  30. $response = $transport->performRequest(
  31. $endpoint->getMethod(),
  32. $endpoint->getURI(),
  33. $endpoint->getParams(),
  34. $endpoint->getBody(),
  35. $endpoint->getOptions()
  36. );
  37. $response = $transport->resultOrFuture($response, $endpoint->getOptions());
  38. if (!($response instanceof FutureArrayInterface)) {
  39. if ($response['status'] === 200) {
  40. return true;
  41. } else {
  42. return false;
  43. }
  44. } else {
  45. // async mode, can't easily resolve this...punt to user
  46. return $response;
  47. }
  48. } catch (Missing404Exception $exception) {
  49. return false;
  50. } catch (RoutingMissingException $exception) {
  51. return false;
  52. }
  53. }
  54. }