1<?php 2 3declare(strict_types = 1); 4 5namespace Elasticsearch\Namespaces; 6 7use Elasticsearch\Endpoints\AbstractEndpoint; 8use Elasticsearch\Transport; 9 10/** 11 * Class AbstractNamespace 12 * 13 * @category Elasticsearch 14 * @package Elasticsearch\Namespaces 15 * @author Zachary Tong <zach@elastic.co> 16 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2 17 * @link http://elastic.co 18 */ 19abstract class AbstractNamespace 20{ 21 /** 22 * @var \Elasticsearch\Transport 23 */ 24 protected $transport; 25 26 /** 27 * @var callable 28 */ 29 protected $endpoints; 30 31 public function __construct(Transport $transport, callable $endpoints) 32 { 33 $this->transport = $transport; 34 $this->endpoints = $endpoints; 35 } 36 37 /** 38 * @return null|mixed 39 */ 40 public function extractArgument(array &$params, string $arg) 41 { 42 if (array_key_exists($arg, $params) === true) { 43 $val = $params[$arg]; 44 unset($params[$arg]); 45 return $val; 46 } else { 47 return null; 48 } 49 } 50 51 protected function performRequest(AbstractEndpoint $endpoint) 52 { 53 $response = $this->transport->performRequest( 54 $endpoint->getMethod(), 55 $endpoint->getURI(), 56 $endpoint->getParams(), 57 $endpoint->getBody(), 58 $endpoint->getOptions() 59 ); 60 61 return $this->transport->resultOrFuture($response, $endpoint->getOptions()); 62 } 63} 64