1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | namespace OpenSearch\Namespaces; |
23: | |
24: | use OpenSearch\EndpointFactoryInterface; |
25: | use OpenSearch\Endpoints\AbstractEndpoint; |
26: | use OpenSearch\LegacyEndpointFactory; |
27: | use OpenSearch\Transport; |
28: | |
29: | abstract class AbstractNamespace |
30: | { |
31: | |
32: | |
33: | |
34: | protected $transport; |
35: | |
36: | protected EndpointFactoryInterface $endpointFactory; |
37: | |
38: | |
39: | |
40: | |
41: | |
42: | |
43: | protected $endpoints; |
44: | |
45: | public function __construct(Transport $transport, callable|EndpointFactoryInterface $endpointFactory) |
46: | { |
47: | $this->transport = $transport; |
48: | if (is_callable($endpointFactory)) { |
49: | @trigger_error('Passing a callable as $endpointFactory param to ' . __METHOD__ . '() is deprecated in 2.3.2 and will be removed in 3.0.0. Pass an instance of \OpenSearch\EndpointFactoryInterface instead.', E_USER_DEPRECATED); |
50: | $endpoints = $endpointFactory; |
51: | $endpointFactory = new LegacyEndpointFactory($endpointFactory); |
52: | } else { |
53: | $endpoints = function ($c) use ($endpointFactory) { |
54: | @trigger_error('The $endpoints property is deprecated in 2.3.2 and will be removed in 3.0.0.', E_USER_DEPRECATED); |
55: | return $endpointFactory->getEndpoint('OpenSearch\\Endpoints\\' . $c); |
56: | }; |
57: | } |
58: | $this->endpoints = $endpoints; |
59: | $this->endpointFactory = $endpointFactory; |
60: | } |
61: | |
62: | |
63: | |
64: | |
65: | public function extractArgument(array &$params, string $arg) |
66: | { |
67: | if (array_key_exists($arg, $params) === true) { |
68: | $val = $params[$arg]; |
69: | unset($params[$arg]); |
70: | return $val; |
71: | } else { |
72: | return null; |
73: | } |
74: | } |
75: | |
76: | protected function performRequest(AbstractEndpoint $endpoint) |
77: | { |
78: | $response = $this->transport->performRequest( |
79: | $endpoint->getMethod(), |
80: | $endpoint->getURI(), |
81: | $endpoint->getParams(), |
82: | $endpoint->getBody(), |
83: | $endpoint->getOptions() |
84: | ); |
85: | |
86: | return $this->transport->resultOrFuture($response, $endpoint->getOptions()); |
87: | } |
88: | } |
89: | |