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\LegacyTransportWrapper; |
28: | use OpenSearch\Transport; |
29: | use OpenSearch\TransportInterface; |
30: | |
31: | abstract class AbstractNamespace |
32: | { |
33: | |
34: | |
35: | |
36: | |
37: | |
38: | protected $transport; |
39: | |
40: | protected TransportInterface $httpTransport; |
41: | |
42: | protected EndpointFactoryInterface $endpointFactory; |
43: | |
44: | |
45: | |
46: | |
47: | |
48: | |
49: | protected $endpoints; |
50: | |
51: | |
52: | |
53: | |
54: | public function __construct(TransportInterface|Transport $transport, callable|EndpointFactoryInterface $endpointFactory) |
55: | { |
56: | if (!$transport instanceof TransportInterface) { |
57: | @trigger_error('Passing an instance of \OpenSearch\Transport to ' . __METHOD__ . '() is deprecated in 2.4.0 and will be removed in 3.0.0. Pass an instance of \OpenSearch\TransportInterface instead.', E_USER_DEPRECATED); |
58: | |
59: | $this->transport = $transport; |
60: | |
61: | $this->httpTransport = new LegacyTransportWrapper($transport); |
62: | } else { |
63: | $this->httpTransport = $transport; |
64: | } |
65: | if (is_callable($endpointFactory)) { |
66: | @trigger_error('Passing a callable as $endpointFactory param to ' . __METHOD__ . '() is deprecated in 2.4.0 and will be removed in 3.0.0. Pass an instance of \OpenSearch\EndpointFactoryInterface instead.', E_USER_DEPRECATED); |
67: | $endpoints = $endpointFactory; |
68: | |
69: | $endpointFactory = new LegacyEndpointFactory($endpointFactory); |
70: | } else { |
71: | $endpoints = function ($c) use ($endpointFactory) { |
72: | @trigger_error('The $endpoints property is deprecated in 2.4.0 and will be removed in 3.0.0.', E_USER_DEPRECATED); |
73: | return $endpointFactory->getEndpoint('OpenSearch\\Endpoints\\' . $c); |
74: | }; |
75: | } |
76: | |
77: | $this->endpoints = $endpoints; |
78: | $this->endpointFactory = $endpointFactory; |
79: | } |
80: | |
81: | |
82: | |
83: | |
84: | public function extractArgument(array &$params, string $arg) |
85: | { |
86: | if (array_key_exists($arg, $params) === true) { |
87: | $val = $params[$arg]; |
88: | unset($params[$arg]); |
89: | return $val; |
90: | } else { |
91: | return null; |
92: | } |
93: | } |
94: | |
95: | protected function performRequest(AbstractEndpoint $endpoint) |
96: | { |
97: | return $this->httpTransport->sendRequest( |
98: | $endpoint->getMethod(), |
99: | $endpoint->getURI(), |
100: | $endpoint->getParams(), |
101: | $endpoint->getBody(), |
102: | $endpoint->getOptions() |
103: | ); |
104: | |
105: | } |
106: | } |
107: | |