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