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 d76ebc9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 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
9 changes: 7 additions & 2 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,17 +336,22 @@ public function __construct(
} else {
$this->httpTransport = $transport;
}

if (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
$endpointFactory = new LegacyEndpointFactory($endpointFactory);
} else {
if ($endpointFactory === null) {
$endpointFactory = new EndpointFactory();
}
$endpoints = function ($c) use ($endpointFactory) {
@trigger_error('The $endpoints property is deprecated in 2.4.0 and will be removed in 3.0.0.', E_USER_DEPRECATED);
return $endpointFactory->getEndpoint('OpenSearch\\Endpoints\\' . $c);
};
}

// @phpstan-ignore property.deprecated
$this->endpoints = $endpoints;
$this->endpointFactory = $endpointFactory;
Expand Down
9 changes: 7 additions & 2 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,17 +89,22 @@ class Client
} else {
$this->httpTransport = $transport;
}

if (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
$endpointFactory = new LegacyEndpointFactory($endpointFactory);
} else {
if ($endpointFactory === null) {
$endpointFactory = new EndpointFactory();
}
$endpoints = function ($c) use ($endpointFactory) {
@trigger_error('The $endpoints property is deprecated in 2.4.0 and will be removed in 3.0.0.', E_USER_DEPRECATED);
return $endpointFactory->getEndpoint('OpenSearch\\Endpoints\\' . $c);
};
}

// @phpstan-ignore property.deprecated
$this->endpoints = $endpoints;
$this->endpointFactory = $endpointFactory;
Expand Down

0 comments on commit d76ebc9

Please sign in to comment.