From bbe2ad3bb1bc46f256bbecc629c9d13f87389c02 Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Sat, 2 Nov 2024 14:07:30 +1100 Subject: [PATCH] Replace endpoint callable with EndpointFactory Signed-off-by: Kim Pepper Signed-off-by: Kim Pepper Signed-off-by: Kim Pepper --- src/OpenSearch/ClientBuilder.php | 46 +----- src/OpenSearch/EndpointFactory.php | 55 +++++++ src/OpenSearch/EndpointFactoryInterface.php | 21 +++ src/OpenSearch/EndpointInterface.php | 77 ++++++++++ .../Namespaces/AbstractNamespace.php | 4 +- tests/ClientTest.php | 16 +- .../MachineLearningNamespaceTest.php | 137 +++++++++--------- tests/Namespaces/SqlNamespaceTest.php | 26 ++-- util/EndpointProxies/createProxy.php | 5 +- .../indices/refreshSearchAnalyzersProxy.php | 3 +- .../ml/createConnectorProxy.php | 3 +- .../ml/deleteConnectorProxy.php | 3 +- util/EndpointProxies/ml/deployModelProxy.php | 3 +- util/EndpointProxies/ml/getConnectorProxy.php | 3 +- .../EndpointProxies/ml/getConnectorsProxy.php | 3 +- .../ml/getModelGroupsProxy.php | 3 +- util/EndpointProxies/ml/getModelProxy.php | 3 +- util/EndpointProxies/ml/predictProxy.php | 3 +- .../EndpointProxies/ml/undeployModelProxy.php | 3 +- .../ml/updateModelGroupProxy.php | 3 +- .../security/changePasswordProxy.php | 3 +- .../security/createActionGroupProxy.php | 5 +- .../security/createRoleMappingProxy.php | 5 +- .../security/createRoleProxy.php | 3 +- .../security/createTenantProxy.php | 3 +- .../security/createUserProxy.php | 3 +- .../security/getActionGroupsProxy.php | 5 +- .../security/getDistinguishedNamesProxy.php | 5 +- .../security/getRoleMappingsProxy.php | 5 +- .../security/getRolesProxy.php | 5 +- .../security/getTenantsProxy.php | 5 +- .../security/getUsersProxy.php | 4 +- .../security/patchActionGroupsProxy.php | 5 +- .../security/patchRoleMappingsProxy.php | 5 +- .../security/patchRolesProxy.php | 5 +- .../security/patchTenantsProxy.php | 5 +- .../security/patchUsersProxy.php | 5 +- util/EndpointProxies/sql/closeCursorProxy.php | 4 +- util/EndpointProxies/sql/explainProxy.php | 4 +- util/EndpointProxies/sql/queryProxy.php | 4 +- util/NamespaceEndpoint.php | 3 +- util/template/client-class | 11 +- util/template/endpoint-function | 5 +- util/template/endpoint-function-bool | 5 +- util/template/new-namespace | 2 +- 45 files changed, 309 insertions(+), 225 deletions(-) create mode 100644 src/OpenSearch/EndpointFactory.php create mode 100644 src/OpenSearch/EndpointFactoryInterface.php create mode 100644 src/OpenSearch/EndpointInterface.php diff --git a/src/OpenSearch/ClientBuilder.php b/src/OpenSearch/ClientBuilder.php index 1865bc3dd..969e41832 100644 --- a/src/OpenSearch/ClientBuilder.php +++ b/src/OpenSearch/ClientBuilder.php @@ -54,10 +54,7 @@ class ClientBuilder */ private $transport; - /** - * @var callable|null - */ - private $endpoint; + private ?EndpointFactoryInterface $endpointFactory = null; /** * @var NamespaceBuilderInterface[] @@ -182,14 +179,6 @@ public function getTransport(): Transport return $this->transport; } - /** - * Can supply second param to Client::__construct() when invoking manually or with dependency injection - */ - public function getEndpoint(): callable - { - return $this->endpoint; - } - /** * Can supply third param to Client::__construct() when invoking manually or with dependency injection * @@ -325,15 +314,9 @@ public function setConnectionPool($connectionPool, array $args = []): ClientBuil return $this; } - /** - * Set the endpoint - * - * @param callable $endpoint - */ - public function setEndpoint(callable $endpoint): ClientBuilder + public function setEndpointFactory(EndpointFactoryInterface $endpointFactory): ClientBuilder { - $this->endpoint = $endpoint; - + $this->endpointFactory = $endpointFactory; return $this; } @@ -671,21 +654,8 @@ public function build(): Client $this->buildTransport(); - if (is_null($this->endpoint)) { - $serializer = $this->serializer; - - $this->endpoint = function ($class) use ($serializer) { - $fullPath = '\\OpenSearch\\Endpoints\\' . $class; - - $reflection = new ReflectionClass($fullPath); - $constructor = $reflection->getConstructor(); - - if ($constructor && $constructor->getParameters()) { - return new $fullPath($serializer); - } else { - return new $fullPath(); - } - }; + if (is_null($this->endpointFactory)) { + $this->endpointFactory = new EndpointFactory($this->serializer); } $registeredNamespaces = []; @@ -696,12 +666,12 @@ public function build(): Client $registeredNamespaces[$builder->getName()] = $builder->getObject($this->transport, $this->serializer); } - return $this->instantiate($this->transport, $this->endpoint, $registeredNamespaces); + return $this->instantiate($this->transport, $this->endpointFactory, $registeredNamespaces); } - protected function instantiate(Transport $transport, callable $endpoint, array $registeredNamespaces): Client + protected function instantiate(Transport $transport, EndpointFactoryInterface $endpointFactory, array $registeredNamespaces): Client { - return new Client($transport, $endpoint, $registeredNamespaces); + return new Client($transport, $endpointFactory, $registeredNamespaces); } private function buildLoggers(): void diff --git a/src/OpenSearch/EndpointFactory.php b/src/OpenSearch/EndpointFactory.php new file mode 100644 index 000000000..65bb5b362 --- /dev/null +++ b/src/OpenSearch/EndpointFactory.php @@ -0,0 +1,55 @@ + + */ + private array $endpoints = []; + + public function __construct( + protected SerializerInterface $serializer, + ) { + } + + /** + * {@inheritdoc} + */ + public function getEndpoint(string $class): AbstractEndpoint + { + if (!isset($this->endpoints[$class])) { + $this->endpoints[$class] = $this->createEndpoint($class); + } + + return $this->endpoints[$class]; + } + + /** + * Creates an endpoint. + * + * @phpstan-template T of AbstractEndpoint + * @phpstan-param class-string $class + * @phpstan-return T + * @throws \ReflectionException + */ + private function createEndpoint(string $class): AbstractEndpoint + { + $reflection = new ReflectionClass($class); + $constructor = $reflection->getConstructor(); + + if ($constructor && $constructor->getParameters()) { + return new $class($this->serializer); + } + return new $class(); + } + +} diff --git a/src/OpenSearch/EndpointFactoryInterface.php b/src/OpenSearch/EndpointFactoryInterface.php new file mode 100644 index 000000000..2e481fc5c --- /dev/null +++ b/src/OpenSearch/EndpointFactoryInterface.php @@ -0,0 +1,21 @@ + $class + * @phpstan-return T + */ + public function getEndpoint(string $class): AbstractEndpoint; + +} diff --git a/src/OpenSearch/EndpointInterface.php b/src/OpenSearch/EndpointInterface.php new file mode 100644 index 000000000..b9e32e0e5 --- /dev/null +++ b/src/OpenSearch/EndpointInterface.php @@ -0,0 +1,77 @@ +transport = $transport; - $this->endpoints = $endpoints; } /** diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 434706078..b580bae5c 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -413,9 +413,9 @@ public function testExtractArgumentIterable() /** @test */ public function sendRawRequest(): void { - $callable = function () {}; $transport = $this->createMock(OpenSearch\Transport::class); - $client = new OpenSearch\Client($transport, $callable, []); + $endpointFactory = $this->createMock(OpenSearch\EndpointFactoryInterface::class); + $client = new OpenSearch\Client($transport, $endpointFactory, []); $transport->expects($this->once())->method('performRequest')->with('GET', '/', [], null, []); @@ -425,9 +425,9 @@ public function sendRawRequest(): void /** @test */ public function sendRawRequestWithBody(): void { - $callable = function () {}; $transport = $this->createMock(OpenSearch\Transport::class); - $client = new OpenSearch\Client($transport, $callable, []); + $endpointFactory = $this->createMock(OpenSearch\EndpointFactoryInterface::class); + $client = new OpenSearch\Client($transport, $endpointFactory, []); $body = ['query' => ['match' => ['text_entry' => 'long live king']]]; $transport->expects($this->once())->method('performRequest')->with('GET', '/shakespeare/_search', [], $body, []); @@ -438,9 +438,9 @@ public function sendRawRequestWithBody(): void /** @test */ public function sendRawRequestWithParams(): void { - $callable = function () {}; $transport = $this->createMock(OpenSearch\Transport::class); - $client = new OpenSearch\Client($transport, $callable, []); + $endpointFactory = $this->createMock(OpenSearch\EndpointFactoryInterface::class); + $client = new OpenSearch\Client($transport, $endpointFactory, []); $params = ['foo' => 'bar']; $transport->expects($this->once())->method('performRequest')->with('GET', '/_search', $params, null, []); @@ -451,9 +451,9 @@ public function sendRawRequestWithParams(): void /** @test */ public function sendRawRequestWithOptions(): void { - $callable = function () {}; $transport = $this->createMock(OpenSearch\Transport::class); - $client = new OpenSearch\Client($transport, $callable, []); + $endpointFactory = $this->createMock(OpenSearch\EndpointFactoryInterface::class); + $client = new OpenSearch\Client($transport, $endpointFactory, []); $options = ['client' => ['future' => 'lazy']]; $transport->expects($this->once())->method('performRequest')->with('GET', '/', [], null, $options); diff --git a/tests/Namespaces/MachineLearningNamespaceTest.php b/tests/Namespaces/MachineLearningNamespaceTest.php index bb5c1237b..9001bfe9e 100644 --- a/tests/Namespaces/MachineLearningNamespaceTest.php +++ b/tests/Namespaces/MachineLearningNamespaceTest.php @@ -2,6 +2,8 @@ namespace OpenSearch\Tests\Namespaces; +use OpenSearch\EndpointFactory; +use OpenSearch\EndpointFactoryInterface; use OpenSearch\Endpoints\Ml\CreateConnector; use OpenSearch\Endpoints\Ml\DeleteConnector; use OpenSearch\Endpoints\Ml\GetConnector; @@ -37,9 +39,9 @@ class MlNamespaceTest extends TestCase public function testCreatingConnector(): void { - $func = static function () { - return new CreateConnector(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new CreateConnector()); $transport = $this->createMock(Transport::class); @@ -51,7 +53,7 @@ public function testCreatingConnector(): void $transport->method('resultOrFuture') ->willReturn([]); - (new MlNamespace($transport, $func))->createConnector([ + (new MlNamespace($transport, $endpointFactory))->createConnector([ 'body' => [ 'foo' => 'bar', ], @@ -61,9 +63,9 @@ public function testCreatingConnector(): void public function testGetConnector(): void { - $func = static function () { - return new GetConnector(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new GetConnector()); $transport = $this->createMock(Transport::class); @@ -73,7 +75,7 @@ public function testGetConnector(): void $transport->method('resultOrFuture') ->willReturn([]); - (new MlNamespace($transport, $func))->getConnector([ + (new MlNamespace($transport, $endpointFactory))->getConnector([ 'id' => 'foobar' ]); } @@ -81,9 +83,9 @@ public function testGetConnector(): void public function testGetConnectors(): void { - $func = static function () { - return new GetConnectors(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new GetConnectors()); $transport = $this->createMock(Transport::class); @@ -98,7 +100,7 @@ public function testGetConnectors(): void $transport->method('resultOrFuture') ->willReturn([]); - (new MlNamespace($transport, $func))->getConnectors([ + (new MlNamespace($transport, $endpointFactory))->getConnectors([ 'body' => [ 'query' => [ 'match_all' => new \StdClass(), @@ -111,9 +113,9 @@ public function testGetConnectors(): void public function testDeleteConnector(): void { - $func = static function () { - return new DeleteConnector(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new DeleteConnector()); $transport = $this->createMock(Transport::class); @@ -123,7 +125,7 @@ public function testDeleteConnector(): void $transport->method('resultOrFuture') ->willReturn([]); - (new MlNamespace($transport, $func))->deleteConnector([ + (new MlNamespace($transport, $endpointFactory))->deleteConnector([ 'connector_id' => 'foobar' ]); } @@ -131,9 +133,9 @@ public function testDeleteConnector(): void public function testRegisterModelGroup(): void { - $func = static function () { - return new RegisterModelGroup(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new RegisterModelGroup()); $transport = $this->createMock(Transport::class); @@ -145,7 +147,7 @@ public function testRegisterModelGroup(): void $transport->method('resultOrFuture') ->willReturn([]); - (new MlNamespace($transport, $func))->registerModelGroup([ + (new MlNamespace($transport, $endpointFactory))->registerModelGroup([ 'body' => [ 'foo' => 'bar', ], @@ -155,9 +157,9 @@ public function testRegisterModelGroup(): void public function testGetModelGroups(): void { - $func = static function () { - return new GetModelGroups(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new GetModelGroups()); $transport = $this->createMock(Transport::class); @@ -172,7 +174,7 @@ public function testGetModelGroups(): void $transport->method('resultOrFuture') ->willReturn([]); - (new MlNamespace($transport, $func))->getModelGroups([ + (new MlNamespace($transport, $endpointFactory))->getModelGroups([ 'body' => [ 'query' => [ 'match_all' => new \StdClass(), @@ -185,9 +187,9 @@ public function testGetModelGroups(): void public function testUpdateModelGroup(): void { - $func = static function () { - return new UpdateModelGroup(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new UpdateModelGroup()); $transport = $this->createMock(Transport::class); @@ -202,7 +204,7 @@ public function testUpdateModelGroup(): void $transport->method('resultOrFuture') ->willReturn([]); - (new MlNamespace($transport, $func))->updateModelGroup([ + (new MlNamespace($transport, $endpointFactory))->updateModelGroup([ 'id' => 'foobar', 'body' => [ 'query' => [ @@ -216,9 +218,9 @@ public function testUpdateModelGroup(): void public function testDeleteModelGroup(): void { - $func = static function () { - return new DeleteModelGroup(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new DeleteModelGroup()); $transport = $this->createMock(Transport::class); @@ -228,7 +230,7 @@ public function testDeleteModelGroup(): void $transport->method('resultOrFuture') ->willReturn([]); - (new MlNamespace($transport, $func))->deleteModelGroup([ + (new MlNamespace($transport, $endpointFactory))->deleteModelGroup([ 'id' => 'foobar' ]); } @@ -236,9 +238,9 @@ public function testDeleteModelGroup(): void public function testRegisterModel(): void { - $func = static function () { - return new RegisterModel(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new RegisterModel()); $transport = $this->createMock(Transport::class); @@ -250,7 +252,7 @@ public function testRegisterModel(): void $transport->method('resultOrFuture') ->willReturn([]); - (new MlNamespace($transport, $func))->registerModel([ + (new MlNamespace($transport, $endpointFactory))->registerModel([ 'body' => [ 'foo' => 'bar', ], @@ -259,10 +261,9 @@ public function testRegisterModel(): void public function testGetModel(): void { - - $func = static function () { - return new GetModel(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new GetModel()); $transport = $this->createMock(Transport::class); @@ -272,17 +273,16 @@ public function testGetModel(): void $transport->method('resultOrFuture') ->willReturn([]); - (new MlNamespace($transport, $func))->getModel([ + (new MlNamespace($transport, $endpointFactory))->getModel([ 'id' => 'foobar', ]); } public function testSearchModels(): void { - - $func = static function () { - return new SearchModels(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new SearchModels()); $transport = $this->createMock(Transport::class); @@ -297,7 +297,7 @@ public function testSearchModels(): void $transport->method('resultOrFuture') ->willReturn([]); - (new MlNamespace($transport, $func))->searchModels([ + (new MlNamespace($transport, $endpointFactory))->searchModels([ 'body' => [ 'query' => [ 'match_all' => new \StdClass(), @@ -309,10 +309,9 @@ public function testSearchModels(): void public function testDeployModel(): void { - - $func = static function () { - return new DeployModel(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new DeployModel()); $transport = $this->createMock(Transport::class); @@ -322,17 +321,16 @@ public function testDeployModel(): void $transport->method('resultOrFuture') ->willReturn([]); - (new MlNamespace($transport, $func))->deployModel([ + (new MlNamespace($transport, $endpointFactory))->deployModel([ 'model_id' => 'foobar', ]); } public function testUnDeployModel(): void { - - $func = static function () { - return new UndeployModel(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new UndeployModel()); $transport = $this->createMock(Transport::class); @@ -342,17 +340,16 @@ public function testUnDeployModel(): void $transport->method('resultOrFuture') ->willReturn([]); - (new MlNamespace($transport, $func))->undeployModel([ + (new MlNamespace($transport, $endpointFactory))->undeployModel([ 'model_id' => 'foobar', ]); } public function testDeleteModel(): void { - - $func = static function () { - return new DeleteModel(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new DeleteModel()); $transport = $this->createMock(Transport::class); @@ -362,17 +359,16 @@ public function testDeleteModel(): void $transport->method('resultOrFuture') ->willReturn([]); - (new MlNamespace($transport, $func))->deleteModel([ + (new MlNamespace($transport, $endpointFactory))->deleteModel([ 'id' => 'foobar', ]); } public function testPredict(): void { - - $func = static function () { - return new Predict(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new Predict()); $transport = $this->createMock(Transport::class); @@ -384,7 +380,7 @@ public function testPredict(): void $transport->method('resultOrFuture') ->willReturn([]); - (new MlNamespace($transport, $func))->predict([ + (new MlNamespace($transport, $endpointFactory))->predict([ 'id' => 'foobar', 'body' => [ 'foo' => 'bar', @@ -394,10 +390,9 @@ public function testPredict(): void public function testGetTask(): void { - - $func = static function () { - return new GetTask(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new GetTask()); $transport = $this->createMock(Transport::class); @@ -407,7 +402,7 @@ public function testGetTask(): void $transport->method('resultOrFuture') ->willReturn([]); - (new MlNamespace($transport, $func))->getTask([ + (new MlNamespace($transport, $endpointFactory))->getTask([ 'id' => 'foobar', ]); } diff --git a/tests/Namespaces/SqlNamespaceTest.php b/tests/Namespaces/SqlNamespaceTest.php index 45dc00974..dae5b5f67 100644 --- a/tests/Namespaces/SqlNamespaceTest.php +++ b/tests/Namespaces/SqlNamespaceTest.php @@ -13,6 +13,8 @@ namespace OpenSearch\Tests\Namespaces; +use OpenSearch\EndpointFactoryInterface; +use OpenSearch\Endpoints\Ml\CreateConnector; use OpenSearch\Endpoints\Sql\CursorClose; use OpenSearch\Endpoints\Sql\Explain; use OpenSearch\Endpoints\Sql\Query; @@ -36,11 +38,11 @@ public function testQuery(): void $transport->method('resultOrFuture') ->willReturn([]); - $func = static function () { - return new Query(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new Query()); - (new SqlNamespace($transport, $func))->query([ + (new SqlNamespace($transport, $endpointFactory))->query([ 'query' => 'select * from test', ]); } @@ -56,11 +58,11 @@ public function testExplain(): void $transport->method('resultOrFuture') ->willReturn([]); - $func = static function () { - return new Explain(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new Explain()); - (new SqlNamespace($transport, $func))->explain([ + (new SqlNamespace($transport, $endpointFactory))->explain([ 'query' => 'select * from test', ]); } @@ -76,11 +78,11 @@ public function testCloseCursor(): void $transport->method('resultOrFuture') ->willReturn([]); - $func = static function () { - return new CursorClose(); - }; + $endpointFactory = $this->createMock(EndpointFactoryInterface::class); + $endpointFactory->method('getEndpoint') + ->willReturn(new CursorClose()); - (new SqlNamespace($transport, $func))->closeCursor([ + (new SqlNamespace($transport, $endpointFactory))->closeCursor([ 'cursor' => 'fooo', ]); } diff --git a/util/EndpointProxies/createProxy.php b/util/EndpointProxies/createProxy.php index 56a75bf64..027272fbd 100644 --- a/util/EndpointProxies/createProxy.php +++ b/util/EndpointProxies/createProxy.php @@ -30,8 +30,9 @@ public function create(array $params = []) $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); - $endpointBuilder = $this->endpoints; - $endpoint = $id ? $endpointBuilder('Create') : $endpointBuilder('Index'); + $endpoint = $id ? + $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Create::class) + : $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Index::class); $endpoint->setParams($params); $endpoint->setId($id); $endpoint->setIndex($index); diff --git a/util/EndpointProxies/indices/refreshSearchAnalyzersProxy.php b/util/EndpointProxies/indices/refreshSearchAnalyzersProxy.php index 4b0497b86..46ce67170 100644 --- a/util/EndpointProxies/indices/refreshSearchAnalyzersProxy.php +++ b/util/EndpointProxies/indices/refreshSearchAnalyzersProxy.php @@ -12,8 +12,7 @@ public function refreshSearchAnalyzers(array $params = []) { $index = $this->extractArgument($params, 'index'); - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Indices\RefreshSearchAnalyzers'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Indices\RefreshSearchAnalyzers::class); $endpoint->setParams($params); $endpoint->setIndex($index); diff --git a/util/EndpointProxies/ml/createConnectorProxy.php b/util/EndpointProxies/ml/createConnectorProxy.php index c9841cfc2..4e7abfe2a 100644 --- a/util/EndpointProxies/ml/createConnectorProxy.php +++ b/util/EndpointProxies/ml/createConnectorProxy.php @@ -13,8 +13,7 @@ public function createConnector(array $params = []): array { $body = $this->extractArgument($params, 'body'); - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Ml\CreateConnector'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\CreateConnector::class); $endpoint->setParams($params); $endpoint->setBody($body); diff --git a/util/EndpointProxies/ml/deleteConnectorProxy.php b/util/EndpointProxies/ml/deleteConnectorProxy.php index b8c7796c5..d677cfdaf 100644 --- a/util/EndpointProxies/ml/deleteConnectorProxy.php +++ b/util/EndpointProxies/ml/deleteConnectorProxy.php @@ -13,8 +13,7 @@ public function deleteConnector(array $params = []): array { $connectorId = $this->extractArgument($params, 'connector_id'); - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Ml\DeleteConnector'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\DeleteConnector::class); $endpoint->setParams($params); $endpoint->setConnectorId($connectorId); diff --git a/util/EndpointProxies/ml/deployModelProxy.php b/util/EndpointProxies/ml/deployModelProxy.php index 804e39145..caed9214b 100644 --- a/util/EndpointProxies/ml/deployModelProxy.php +++ b/util/EndpointProxies/ml/deployModelProxy.php @@ -15,8 +15,7 @@ public function deployModel(array $params = []): array { $modelId = $this->extractArgument($params, 'model_id'); $body = $this->extractArgument($params, 'body'); - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Ml\DeployModel'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\DeployModel::class); $endpoint->setParams($params); $endpoint->setModelId($modelId); if ($body) { diff --git a/util/EndpointProxies/ml/getConnectorProxy.php b/util/EndpointProxies/ml/getConnectorProxy.php index 5988c7556..739adfc50 100644 --- a/util/EndpointProxies/ml/getConnectorProxy.php +++ b/util/EndpointProxies/ml/getConnectorProxy.php @@ -13,8 +13,7 @@ public function getConnector(array $params = []): array { $id = $this->extractArgument($params, 'id'); - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Ml\GetConnector'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\GetConnector::class); $endpoint->setParams($params); $endpoint->setId($id); diff --git a/util/EndpointProxies/ml/getConnectorsProxy.php b/util/EndpointProxies/ml/getConnectorsProxy.php index 55e03fa88..01faad25e 100644 --- a/util/EndpointProxies/ml/getConnectorsProxy.php +++ b/util/EndpointProxies/ml/getConnectorsProxy.php @@ -21,8 +21,7 @@ public function getConnectors(array $params = []): array ]; } $body = $this->extractArgument($params, 'body'); - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Ml\GetConnectors'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\GetConnectors::class); $endpoint->setBody($body); return $this->performRequest($endpoint); diff --git a/util/EndpointProxies/ml/getModelGroupsProxy.php b/util/EndpointProxies/ml/getModelGroupsProxy.php index 8d7c65764..2126e684a 100644 --- a/util/EndpointProxies/ml/getModelGroupsProxy.php +++ b/util/EndpointProxies/ml/getModelGroupsProxy.php @@ -21,8 +21,7 @@ public function getModelGroups(array $params = []): array ]; } $body = $this->extractArgument($params, 'body'); - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Ml\GetModelGroups'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\GetModelGroups::class); $endpoint->setBody($body); return $this->performRequest($endpoint); diff --git a/util/EndpointProxies/ml/getModelProxy.php b/util/EndpointProxies/ml/getModelProxy.php index 39e514953..f5afef39e 100644 --- a/util/EndpointProxies/ml/getModelProxy.php +++ b/util/EndpointProxies/ml/getModelProxy.php @@ -13,8 +13,7 @@ public function getModel(array $params = []): array { $id = $this->extractArgument($params, 'id'); - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Ml\GetModel'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\GetModel::class); $endpoint->setParams($params); $endpoint->setId($id); diff --git a/util/EndpointProxies/ml/predictProxy.php b/util/EndpointProxies/ml/predictProxy.php index e9b275faa..cc0e8f7d0 100644 --- a/util/EndpointProxies/ml/predictProxy.php +++ b/util/EndpointProxies/ml/predictProxy.php @@ -15,8 +15,7 @@ public function predict(array $params = []): array { $id = $this->extractArgument($params, 'id'); $body = $this->extractArgument($params, 'body'); - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Ml\Predict'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\Predict::class); $endpoint->setParams($params); $endpoint->setId($id); $endpoint->setBody($body); diff --git a/util/EndpointProxies/ml/undeployModelProxy.php b/util/EndpointProxies/ml/undeployModelProxy.php index 7711ae313..219f664ff 100644 --- a/util/EndpointProxies/ml/undeployModelProxy.php +++ b/util/EndpointProxies/ml/undeployModelProxy.php @@ -15,8 +15,7 @@ public function undeployModel(array $params = []): array { $modelId = $this->extractArgument($params, 'model_id'); $body = $this->extractArgument($params, 'body'); - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Ml\UndeployModel'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\UndeployModel::class); $endpoint->setParams($params); $endpoint->setModelId($modelId); if ($body) { diff --git a/util/EndpointProxies/ml/updateModelGroupProxy.php b/util/EndpointProxies/ml/updateModelGroupProxy.php index 166f048b3..aad4c72ad 100644 --- a/util/EndpointProxies/ml/updateModelGroupProxy.php +++ b/util/EndpointProxies/ml/updateModelGroupProxy.php @@ -15,8 +15,7 @@ public function updateModelGroup(array $params = []): array { $id = $this->extractArgument($params, 'id'); $body = $this->extractArgument($params, 'body'); - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Ml\UpdateModelGroup'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\UpdateModelGroup::class); $endpoint->setParams($params); $endpoint->setBody($body); $endpoint->setId($id); diff --git a/util/EndpointProxies/security/changePasswordProxy.php b/util/EndpointProxies/security/changePasswordProxy.php index b99c9e508..69c62c74e 100644 --- a/util/EndpointProxies/security/changePasswordProxy.php +++ b/util/EndpointProxies/security/changePasswordProxy.php @@ -26,8 +26,7 @@ public function changePassword(array $params = []) ]; } - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Security\ChangePassword'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\ChangePassword::class); $endpoint->setParams($params); $endpoint->setBody($body); diff --git a/util/EndpointProxies/security/createActionGroupProxy.php b/util/EndpointProxies/security/createActionGroupProxy.php index adebb27a6..e252361e9 100644 --- a/util/EndpointProxies/security/createActionGroupProxy.php +++ b/util/EndpointProxies/security/createActionGroupProxy.php @@ -25,9 +25,8 @@ public function createActionGroup(array $params = []) 'allowed_actions' => $this->extractArgument($params, 'allowed_actions'), ]; } - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Security\CreateActionGroup'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\CreateActionGroup::class); $endpoint->setParams($params); $endpoint->setActionGroup($action_group); $endpoint->setBody($body); diff --git a/util/EndpointProxies/security/createRoleMappingProxy.php b/util/EndpointProxies/security/createRoleMappingProxy.php index 550fe69bd..65385e636 100644 --- a/util/EndpointProxies/security/createRoleMappingProxy.php +++ b/util/EndpointProxies/security/createRoleMappingProxy.php @@ -29,9 +29,8 @@ public function createRoleMapping(array $params = []) 'users' => $this->extractArgument($params, 'users'), ]); } - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Security\CreateRoleMapping'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\CreateRoleMapping::class); $endpoint->setParams($params); $endpoint->setRole($role); $endpoint->setBody($body); diff --git a/util/EndpointProxies/security/createRoleProxy.php b/util/EndpointProxies/security/createRoleProxy.php index a7b92840a..9e0f78daf 100644 --- a/util/EndpointProxies/security/createRoleProxy.php +++ b/util/EndpointProxies/security/createRoleProxy.php @@ -30,8 +30,7 @@ public function createRole(array $params = []) ]); } - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Security\CreateRole'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\CreateRole::class); $endpoint->setParams($params); $endpoint->setRole($role); $endpoint->setBody($body); diff --git a/util/EndpointProxies/security/createTenantProxy.php b/util/EndpointProxies/security/createTenantProxy.php index f92f6b4fb..9fdc19912 100644 --- a/util/EndpointProxies/security/createTenantProxy.php +++ b/util/EndpointProxies/security/createTenantProxy.php @@ -26,8 +26,7 @@ public function createTenant(array $params = []) ]; } - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Security\CreateTenant'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\CreateTenant::class); $endpoint->setParams($params); $endpoint->setTenant($tenant); $endpoint->setBody($body); diff --git a/util/EndpointProxies/security/createUserProxy.php b/util/EndpointProxies/security/createUserProxy.php index 452aa96e2..fd79e8c82 100644 --- a/util/EndpointProxies/security/createUserProxy.php +++ b/util/EndpointProxies/security/createUserProxy.php @@ -32,8 +32,7 @@ public function createUser(array $params = []) ]); } - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Security\CreateUser'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\CreateUser::class); $endpoint->setParams($params); $endpoint->setUsername($username); $endpoint->setBody($body); diff --git a/util/EndpointProxies/security/getActionGroupsProxy.php b/util/EndpointProxies/security/getActionGroupsProxy.php index 9c015db98..d3484cb2a 100644 --- a/util/EndpointProxies/security/getActionGroupsProxy.php +++ b/util/EndpointProxies/security/getActionGroupsProxy.php @@ -17,13 +17,12 @@ */ public function getActionGroups(array $params = []) { - $endpointBuilder = $this->endpoints; if (isset($params['action_group'])) { - $endpoint = $endpointBuilder('Security\GetActionGroup'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\GetActionGroup::class); $action_group = $this->extractArgument($params, 'action_group'); $endpoint->setActionGroup($action_group); } else { - $endpoint = $endpointBuilder('Security\GetActionGroups'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\GetActionGroups::class); } $endpoint->setParams($params); diff --git a/util/EndpointProxies/security/getDistinguishedNamesProxy.php b/util/EndpointProxies/security/getDistinguishedNamesProxy.php index e3a478151..a62665780 100644 --- a/util/EndpointProxies/security/getDistinguishedNamesProxy.php +++ b/util/EndpointProxies/security/getDistinguishedNamesProxy.php @@ -19,13 +19,12 @@ */ public function getDistinguishedNames(array $params = []) { - $endpointBuilder = $this->endpoints; if (isset($params['cluster_name'])) { - $endpoint = $endpointBuilder('Security\GetDistinguishedName'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\GetDistinguishedName::class); $cluster_name = $this->extractArgument($params, 'cluster_name'); $endpoint->setClusterName($cluster_name); } else { - $endpoint = $endpointBuilder('Security\GetDistinguishedNames'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\GetDistinguishedNames::class); } $endpoint->setParams($params); diff --git a/util/EndpointProxies/security/getRoleMappingsProxy.php b/util/EndpointProxies/security/getRoleMappingsProxy.php index b04a7c298..1128c9502 100644 --- a/util/EndpointProxies/security/getRoleMappingsProxy.php +++ b/util/EndpointProxies/security/getRoleMappingsProxy.php @@ -18,13 +18,12 @@ */ public function getRoleMappings(array $params = []) { - $endpointBuilder = $this->endpoints; if (isset($params['role'])) { - $endpoint = $endpointBuilder('Security\GetRoleMapping'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\GetRoleMapping::class); $role = $this->extractArgument($params, 'role'); $endpoint->setRole($role); } else { - $endpoint = $endpointBuilder('Security\GetRoleMappings'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\GetRoleMappings::class); } $endpoint->setParams($params); diff --git a/util/EndpointProxies/security/getRolesProxy.php b/util/EndpointProxies/security/getRolesProxy.php index f90cd7477..480b1f98d 100644 --- a/util/EndpointProxies/security/getRolesProxy.php +++ b/util/EndpointProxies/security/getRolesProxy.php @@ -18,13 +18,12 @@ */ public function getRoles(array $params = []) { - $endpointBuilder = $this->endpoints; if (isset($params['role'])) { - $endpoint = $endpointBuilder('Security\GetRole'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\GetRole::class); $role = $this->extractArgument($params, 'role'); $endpoint->setRole($role); } else { - $endpoint = $endpointBuilder('Security\GetRoles'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\GetRoles::class); } $endpoint->setParams($params); diff --git a/util/EndpointProxies/security/getTenantsProxy.php b/util/EndpointProxies/security/getTenantsProxy.php index 698748020..13bba49b2 100644 --- a/util/EndpointProxies/security/getTenantsProxy.php +++ b/util/EndpointProxies/security/getTenantsProxy.php @@ -18,13 +18,12 @@ */ public function getTenants(array $params = []) { - $endpointBuilder = $this->endpoints; if (isset($params['tenant'])) { - $endpoint = $endpointBuilder('Security\GetTenant'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\GetTenant::class); $tenant = $this->extractArgument($params, 'tenant'); $endpoint->setTenant($tenant); } else { - $endpoint = $endpointBuilder('Security\GetTenants'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\GetTenants::class); } $endpoint->setParams($params); diff --git a/util/EndpointProxies/security/getUsersProxy.php b/util/EndpointProxies/security/getUsersProxy.php index 923861558..35c9a2574 100644 --- a/util/EndpointProxies/security/getUsersProxy.php +++ b/util/EndpointProxies/security/getUsersProxy.php @@ -21,11 +21,11 @@ public function getUsers(array $params = []): array $endpointBuilder = $this->endpoints; if (isset($params['username'])) { - $endpoint = $endpointBuilder('Security\GetUser'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\GetUser::class); $username = $this->extractArgument($params, 'username'); $endpoint->setUsername($username); } else { - $endpoint = $endpointBuilder('Security\GetUsers'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\GetUsers::class); } $endpoint->setParams($params); diff --git a/util/EndpointProxies/security/patchActionGroupsProxy.php b/util/EndpointProxies/security/patchActionGroupsProxy.php index e262947e2..ef0d1bba9 100644 --- a/util/EndpointProxies/security/patchActionGroupsProxy.php +++ b/util/EndpointProxies/security/patchActionGroupsProxy.php @@ -23,13 +23,12 @@ public function patchActionGroups(array $params = []) $body = $this->extractArgument($params, 'ops') ?? []; } - $endpointBuilder = $this->endpoints; if (isset($params['action_group'])) { - $endpoint = $endpointBuilder('Security\PatchActionGroup'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\PatchActionGroup::class); $action_group = $this->extractArgument($params, 'action_group'); $endpoint->setActionGroup($action_group); } else { - $endpoint = $endpointBuilder('Security\PatchActionGroups'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\PatchActionGroups::class); } $endpoint->setParams($params); $endpoint->setBody($body); diff --git a/util/EndpointProxies/security/patchRoleMappingsProxy.php b/util/EndpointProxies/security/patchRoleMappingsProxy.php index f7ac213b9..6f71092e9 100644 --- a/util/EndpointProxies/security/patchRoleMappingsProxy.php +++ b/util/EndpointProxies/security/patchRoleMappingsProxy.php @@ -22,13 +22,12 @@ public function patchRoleMappings(array $params = []) $body = $this->extractArgument($params, 'ops') ?? []; } - $endpointBuilder = $this->endpoints; if (isset($params['role'])) { - $endpoint = $endpointBuilder('Security\PatchRoleMapping'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\PatchRoleMapping::class); $role = $this->extractArgument($params, 'role'); $endpoint->setRole($role); } else { - $endpoint = $endpointBuilder('Security\PatchRoleMappings'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\PatchRoleMappings::class); } $endpoint->setParams($params); $endpoint->setBody($body); diff --git a/util/EndpointProxies/security/patchRolesProxy.php b/util/EndpointProxies/security/patchRolesProxy.php index eed70d9b7..e02cc8e48 100644 --- a/util/EndpointProxies/security/patchRolesProxy.php +++ b/util/EndpointProxies/security/patchRolesProxy.php @@ -22,13 +22,12 @@ public function patchRoles(array $params = []) $body = $this->extractArgument($params, 'ops') ?? []; } - $endpointBuilder = $this->endpoints; if (isset($params['role'])) { - $endpoint = $endpointBuilder('Security\PatchRole'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\PatchRole::class); $role = $this->extractArgument($params, 'role'); $endpoint->setRole($role); } else { - $endpoint = $endpointBuilder('Security\PatchRoles'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\PatchRoles::class); } $endpoint->setParams($params); diff --git a/util/EndpointProxies/security/patchTenantsProxy.php b/util/EndpointProxies/security/patchTenantsProxy.php index 10d6fa01b..899f0d9a5 100644 --- a/util/EndpointProxies/security/patchTenantsProxy.php +++ b/util/EndpointProxies/security/patchTenantsProxy.php @@ -22,13 +22,12 @@ public function patchTenants(array $params = []) $body = $this->extractArgument($params, 'ops') ?? []; } - $endpointBuilder = $this->endpoints; if (isset($params['tenant'])) { - $endpoint = $endpointBuilder('Security\PatchTenant'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\PatchTenant::class); $tenant = $this->extractArgument($params, 'tenant'); $endpoint->setTenant($tenant); } else { - $endpoint = $endpointBuilder('Security\PatchTenants'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\PatchTenants::class); } $endpoint->setParams($params); diff --git a/util/EndpointProxies/security/patchUsersProxy.php b/util/EndpointProxies/security/patchUsersProxy.php index 81cba4171..9af53a8a2 100644 --- a/util/EndpointProxies/security/patchUsersProxy.php +++ b/util/EndpointProxies/security/patchUsersProxy.php @@ -22,13 +22,12 @@ public function patchUsers(array $params = []) $body = $this->extractArgument($params, 'ops') ?? []; } - $endpointBuilder = $this->endpoints; if (isset($params['username'])) { - $endpoint = $endpointBuilder('Security\PatchUser'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\PatchUser::class); $username = $this->extractArgument($params, 'username'); $endpoint->setUsername($username); } else { - $endpoint = $endpointBuilder('Security\PatchUsers'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\PatchUsers::class); } $endpoint->setParams($params); diff --git a/util/EndpointProxies/sql/closeCursorProxy.php b/util/EndpointProxies/sql/closeCursorProxy.php index f8f4502f1..66a7b9bdc 100644 --- a/util/EndpointProxies/sql/closeCursorProxy.php +++ b/util/EndpointProxies/sql/closeCursorProxy.php @@ -11,9 +11,7 @@ */ public function closeCursor(array $params): array { - $endpointBuilder = $this->endpoints; - - $endpoint = $endpointBuilder('Sql\Close'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Sql\Close::class); $endpoint->setBody(array_filter([ 'cursor' => $this->extractArgument($params, 'cursor'), ])); diff --git a/util/EndpointProxies/sql/explainProxy.php b/util/EndpointProxies/sql/explainProxy.php index ac0a89cef..16ecf4a13 100644 --- a/util/EndpointProxies/sql/explainProxy.php +++ b/util/EndpointProxies/sql/explainProxy.php @@ -11,12 +11,10 @@ */ public function explain(array $params): array { - $endpointBuilder = $this->endpoints; - $body = $this->extractArgument($params, 'body') ?? []; $query = $this->extractArgument($params, 'query'); - $endpoint = $endpointBuilder('Sql\Explain'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Sql\Explain::class); $endpoint->setBody(array_merge($body, [ 'query' => $query, ])); diff --git a/util/EndpointProxies/sql/queryProxy.php b/util/EndpointProxies/sql/queryProxy.php index b4d2e439d..886810aef 100644 --- a/util/EndpointProxies/sql/queryProxy.php +++ b/util/EndpointProxies/sql/queryProxy.php @@ -15,9 +15,7 @@ */ public function query(array $params): array { - $endpointBuilder = $this->endpoints; - - $endpoint = $endpointBuilder('Sql\Query'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Sql\Query::class); $body = $this->extractArgument($params, 'body') ?? []; $endpoint->setBody(array_merge($body, array_filter([ 'query' => $this->extractArgument($params, 'query'), diff --git a/util/NamespaceEndpoint.php b/util/NamespaceEndpoint.php index b8c7dfb4e..5c748fee9 100644 --- a/util/NamespaceEndpoint.php +++ b/util/NamespaceEndpoint.php @@ -138,7 +138,8 @@ protected function renderEndpoint(Endpoint $endpoint): string } else { $endpointClass = NamespaceEndpoint::normalizeName($endpoint->namespace) . '\\' . $endpoint->getClassName(); } - return str_replace(':EndpointClass', $endpointClass, $code); + $fullClass = '\\OpenSearch\\Endpoints\\' . $endpointClass; + return str_replace(':EndpointClass', $fullClass, $code); } public static function normalizeName(string $name): string diff --git a/util/template/client-class b/util/template/client-class index e3ed316fa..c494e672d 100644 --- a/util/template/client-class +++ b/util/template/client-class @@ -46,10 +46,7 @@ class Client */ protected $params; - /** - * @var callable - */ - protected $endpoints; + protected EndpointFactoryInterface $endpointFactory; /** * @var NamespaceBuilderInterface[] @@ -61,13 +58,13 @@ class Client * Client constructor * * @param Transport $transport - * @param callable $endpoint + * @param EndpointFactoryInterface $endpointFactory * @param NamespaceBuilderInterface[] $registeredNamespaces */ - public function __construct(Transport $transport, callable $endpoint, array $registeredNamespaces) + public function __construct(Transport $transport, EndpointFactoryInterface $endpointFactory, array $registeredNamespaces) { $this->transport = $transport; - $this->endpoints = $endpoint; + $this->endpointFactory = $endpointFactory; :new-namespaces $this->registeredNamespaces = $registeredNamespaces; } diff --git a/util/template/endpoint-function b/util/template/endpoint-function index d5d0a0541..a96c37c51 100644 --- a/util/template/endpoint-function +++ b/util/template/endpoint-function @@ -2,9 +2,8 @@ public function :endpoint(array $params = []) { :extract - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder(':EndpointClass'); + $endpoint = $this->endpointFactory->getEndpoint(:EndpointClass::class); $endpoint->setParams($params); :setparam return $this->performRequest($endpoint); - } \ No newline at end of file + } diff --git a/util/template/endpoint-function-bool b/util/template/endpoint-function-bool index d4e6945d9..d4c90d6d4 100644 --- a/util/template/endpoint-function-bool +++ b/util/template/endpoint-function-bool @@ -5,9 +5,8 @@ // manually make this verbose so we can check status code $params['client']['verbose'] = true; - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder(':EndpointClass'); + $endpoint = $this->endpointFactory->getEndpoint(:EndpointClass::class); $endpoint->setParams($params); :setparam return BooleanRequestWrapper::performRequest($endpoint, $this->transport); - } \ No newline at end of file + } diff --git a/util/template/new-namespace b/util/template/new-namespace index 3c4b354ce..1a7bff8bd 100644 --- a/util/template/new-namespace +++ b/util/template/new-namespace @@ -1 +1 @@ - $this->:name = new :namespace($transport, $endpoint); + $this->:name = new :namespace($transport, $this->endpointFactory);