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 GuzzleHttp\Ring\Future\FutureArrayInterface; |
25: | use OpenSearch\Common\Exceptions\Missing404Exception; |
26: | use OpenSearch\Common\Exceptions\RoutingMissingException; |
27: | use OpenSearch\Endpoints\AbstractEndpoint; |
28: | use OpenSearch\Exception\NotFoundHttpException; |
29: | use OpenSearch\Transport; |
30: | use OpenSearch\TransportInterface; |
31: | |
32: | abstract class BooleanRequestWrapper |
33: | { |
34: | |
35: | |
36: | |
37: | |
38: | |
39: | |
40: | |
41: | |
42: | public static function sendRequest(AbstractEndpoint $endpoint, TransportInterface $transport): bool |
43: | { |
44: | try { |
45: | $transport->sendRequest( |
46: | $endpoint->getMethod(), |
47: | $endpoint->getURI(), |
48: | $endpoint->getParams(), |
49: | $endpoint->getBody(), |
50: | $endpoint->getOptions() |
51: | ); |
52: | |
53: | } catch (NotFoundHttpException|RoutingMissingException $e) { |
54: | |
55: | return false; |
56: | } |
57: | return true; |
58: | } |
59: | |
60: | |
61: | |
62: | |
63: | |
64: | |
65: | |
66: | |
67: | |
68: | public static function performRequest(AbstractEndpoint $endpoint, Transport $transport) |
69: | { |
70: | @trigger_error( |
71: | __METHOD__ . '() is deprecated in 2.4.0 and will be removed in 3.0.0. Use \OpenSearch\Namespaces\BooleanRequestWrapper::sendRequest() instead.' |
72: | ); |
73: | try { |
74: | $response = $transport->performRequest( |
75: | $endpoint->getMethod(), |
76: | $endpoint->getURI(), |
77: | $endpoint->getParams(), |
78: | $endpoint->getBody(), |
79: | $endpoint->getOptions() |
80: | ); |
81: | |
82: | $response = $transport->resultOrFuture($response, $endpoint->getOptions()); |
83: | if (!($response instanceof FutureArrayInterface)) { |
84: | if ($response['status'] === 200) { |
85: | return true; |
86: | } else { |
87: | return false; |
88: | } |
89: | } else { |
90: | |
91: | return $response; |
92: | } |
93: | } catch (Missing404Exception $exception) { |
94: | return false; |
95: | } catch (RoutingMissingException $exception) { |
96: | return false; |
97: | } |
98: | } |
99: | } |
100: | |