Skip to content

Commit

Permalink
Address @stof feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Kim Pepper <[email protected]>
  • Loading branch information
kimpepper committed Dec 17, 2024
1 parent 48b3864 commit 6dc6523
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
- [Upgrading OpenSearch PHP Client](#upgrading-opensearch-php-client)
- [Upgrading to >= 2.0.0](#upgrading-to--200)
- [Upgrading to >= 2.0.0](#upgrading-to--240)
- [HTTP Client Auto-Discovery](#http-client-auto-discovery)
- [Configuring Guzzle HTTP Client in 2.x](#configuring-guzzle-http-client-in-2x)
- [Configuring Symfony HTTP Client in 2.x](#configuring-symfony-http-client-in-2x)

# Upgrading OpenSearch PHP Client

## Upgrading to >= 2.0.0
## Upgrading to >= 2.4.0

openseach-php removes the hard-coded dependency on the [Guzzle HTTP client](https://docs.guzzlephp.org/en/stable/#) and switches to the following PSR interfaces:

Expand Down
5 changes: 0 additions & 5 deletions src/OpenSearch/Aws/SigningClientDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ public function __construct(
protected CredentialsInterface $credentials,
protected SignatureInterface $signer,
) {
if (!class_exists(SignatureInterface::class)) {
throw new \RuntimeException(
'The AWS SDK for PHP must be installed in order to use the AWS signing client.'
);
}
}

public function sendRequest(RequestInterface $request): ResponseInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Common\Exceptions;

@trigger_error(__CLASS__ . ' is deprecated in 2.3.2 and will be removed in 3.0.0.', E_USER_DEPRECATED);
@trigger_error(BadMethodCallException::class . ' is deprecated in 2.3.2 and will be removed in 3.0.0.', E_USER_DEPRECATED);

/**
* BadMethodCallException
Expand Down
4 changes: 3 additions & 1 deletion src/OpenSearch/EndpointInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ public function setId(int|string|null $docID): static;
/**
* Get the body of the request.
*/
public function getBody(): string|iterable|null;
public function getBody(): string|array|null;

/**
* Set the body of the request.
*
* @param string|iterable<string,mixed>|null $body
*/
public function setBody(string|iterable|null $body): static;

Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/AbstractEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function setId(int|string|null $docID): static
return $this;
}

public function getBody(): string|iterable|null
public function getBody(): string|array|null
{
return $this->body;
}
Expand Down
12 changes: 9 additions & 3 deletions src/OpenSearch/Namespaces/BooleanRequestWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ abstract class BooleanRequestWrapper
/**
* Send a request with a boolean response.
*
* Throwing a client exception will return FALSE, otherwise TRUE is returned.
* @return bool
* Returns FALSE for a 404 error, otherwise TRUE.
*
* @throws \Psr\Http\Client\ClientExceptionInterface
*/
public static function sendRequest(AbstractEndpoint $endpoint, TransportInterface $transport): bool
{
Expand All @@ -46,8 +49,11 @@ public static function sendRequest(AbstractEndpoint $endpoint, TransportInterfac
$endpoint->getBody(),
$endpoint->getOptions()
);
} catch (ClientExceptionInterface) {
return false;
} catch (ClientExceptionInterface $e) {
if ($e->getCode() === 404) {
return false;
}
throw $e;
}
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions src/OpenSearch/RequestFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ interface RequestFactoryInterface
{
/**
* Create a new request.
*
* @param array<string, mixed> $params
* @param string|array<string, mixed>|null $body
* @param array<string, string> $headers
*/
public function createRequest(
string $method,
Expand Down
6 changes: 5 additions & 1 deletion src/OpenSearch/TransportInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ interface TransportInterface
/**
* Create a new request.
*
* @param array<string, mixed> $params
* @param string|array<string, mixed>|null $body
* @param array<string, string> $headers
*
* @throws \Psr\Http\Client\ClientExceptionInterface
*/
public function sendRequest(
string $method,
string $uri,
array $params = [],
mixed $body = null,
string|array|null $body = null,
array $headers = [],
): array|string|null;

Expand Down
2 changes: 1 addition & 1 deletion tests/Endpoints/AbstractEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
class AbstractEndpointTest extends TestCase
{
private EndpointInterface|MockObject $endpoint;
private EndpointInterface&MockObject $endpoint;

protected function setUp(): void
{
Expand Down

0 comments on commit 6dc6523

Please sign in to comment.