Skip to content

Commit

Permalink
Make EndpointFactory and optional Client constructor param
Browse files Browse the repository at this point in the history
Signed-off-by: Kim Pepper <[email protected]>
  • Loading branch information
kimpepper committed Feb 27, 2025
1 parent 88235f6 commit c5a9173
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/OpenSearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions util/template/client-class
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit c5a9173

Please sign in to comment.