diff --git a/CHANGELOG.md b/CHANGELOG.md index 12c7fadb..8d16f050 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Added ### Changed +- Updated Client constructor to make EndpointFactory and optional parameter. ### Deprecated ### Removed ### Fixed diff --git a/src/OpenSearch/Client.php b/src/OpenSearch/Client.php index 8c105545..edaccc60 100644 --- a/src/OpenSearch/Client.php +++ b/src/OpenSearch/Client.php @@ -317,14 +317,14 @@ class Client * Client constructor * * @param TransportInterface|Transport $transport - * @param callable|EndpointFactoryInterface $endpointFactory + * @param callable|EndpointFactoryInterface|null $endpointFactory * @param NamespaceBuilderInterface[] $registeredNamespaces * * @phpstan-ignore parameter.deprecatedClass */ public function __construct( TransportInterface|Transport $transport, - callable|EndpointFactoryInterface $endpointFactory, + callable|EndpointFactoryInterface|null $endpointFactory, array $registeredNamespaces = [], ) { if (!$transport instanceof TransportInterface) { @@ -336,7 +336,9 @@ public function __construct( } else { $this->httpTransport = $transport; } - if (is_callable($endpointFactory)) { + if ($endpointFactory === null) { + $endpointFactory = new EndpointFactory(); + } elseif (is_callable($endpointFactory)) { @trigger_error('Passing a callable as the $endpointFactory param in ' . __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); $endpoints = $endpointFactory; // @phpstan-ignore new.deprecated diff --git a/util/template/client-class b/util/template/client-class index b01e8f2a..d8b0d3e8 100644 --- a/util/template/client-class +++ b/util/template/client-class @@ -70,14 +70,14 @@ class Client * Client constructor * * @param TransportInterface|Transport $transport - * @param callable|EndpointFactoryInterface $endpointFactory + * @param callable|EndpointFactoryInterface|null $endpointFactory * @param NamespaceBuilderInterface[] $registeredNamespaces * * @phpstan-ignore parameter.deprecatedClass */ public function __construct( TransportInterface|Transport $transport, - callable|EndpointFactoryInterface $endpointFactory, + callable|EndpointFactoryInterface|null $endpointFactory, array $registeredNamespaces = [], ) { if (!$transport instanceof TransportInterface) { @@ -89,7 +89,9 @@ class Client } else { $this->httpTransport = $transport; } - if (is_callable($endpointFactory)) { + if ($endpointFactory === null) { + $endpointFactory = new EndpointFactory(); + } elseif (is_callable($endpointFactory)) { @trigger_error('Passing a callable as the $endpointFactory param in ' . __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); $endpoints = $endpointFactory; // @phpstan-ignore new.deprecated