1<?php 2/** 3 * Elasticsearch PHP client 4 * 5 * @link https://github.com/elastic/elasticsearch-php/ 6 * @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co) 7 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 8 * @license https://www.gnu.org/licenses/lgpl-2.1.html GNU Lesser General Public License, Version 2.1 9 * 10 * Licensed to Elasticsearch B.V under one or more agreements. 11 * Elasticsearch B.V licenses this file to you under the Apache 2.0 License or 12 * the GNU Lesser General Public License, Version 2.1, at your option. 13 * See the LICENSE file in the project root for more information. 14 */ 15 16 17declare(strict_types = 1); 18 19namespace Elasticsearch\Namespaces; 20 21use Elasticsearch\Endpoints\AbstractEndpoint; 22use Elasticsearch\Transport; 23 24abstract class AbstractNamespace 25{ 26 /** 27 * @var \Elasticsearch\Transport 28 */ 29 protected $transport; 30 31 /** 32 * @var callable 33 */ 34 protected $endpoints; 35 36 public function __construct(Transport $transport, callable $endpoints) 37 { 38 $this->transport = $transport; 39 $this->endpoints = $endpoints; 40 } 41 42 /** 43 * @return null|mixed 44 */ 45 public function extractArgument(array &$params, string $arg) 46 { 47 if (array_key_exists($arg, $params) === true) { 48 $val = $params[$arg]; 49 unset($params[$arg]); 50 return $val; 51 } else { 52 return null; 53 } 54 } 55 56 protected function performRequest(AbstractEndpoint $endpoint) 57 { 58 $response = $this->transport->performRequest( 59 $endpoint->getMethod(), 60 $endpoint->getURI(), 61 $endpoint->getParams(), 62 $endpoint->getBody(), 63 $endpoint->getOptions() 64 ); 65 66 return $this->transport->resultOrFuture($response, $endpoint->getOptions()); 67 } 68} 69