-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Client factories for Guzzle and Symfony
Signed-off-by: Kim Pepper <[email protected]>
- Loading branch information
Showing
12 changed files
with
200 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace OpenSearch; | ||
|
||
/** | ||
* Creates an OpenSearch client. | ||
*/ | ||
interface ClientFactoryInterface | ||
{ | ||
/** | ||
* Creates a new OpenSearch client. | ||
* | ||
* @param array<string,mixed> $options | ||
* The options to use when creating the client. The options are specific to the HTTP client implementation. | ||
*/ | ||
public function create(array $options): Client; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenSearch; | ||
|
||
use OpenSearch\HttpClient\GuzzleHttpClientFactory; | ||
use Psr\Log\LoggerInterface; | ||
use GuzzleHttp\Psr7\HttpFactory; | ||
use OpenSearch\Serializers\SmartSerializer; | ||
|
||
/** | ||
* Creates an OpenSearch client using Guzzle. | ||
*/ | ||
class GuzzleClientFactory implements ClientFactoryInterface | ||
{ | ||
public function __construct( | ||
protected int $maxRetries = 0, | ||
protected ?LoggerInterface $logger = null, | ||
) { | ||
} | ||
|
||
/** | ||
* @param array<string,mixed> $options | ||
* The Guzzle client options. | ||
*/ | ||
public function create(array $options): Client | ||
{ | ||
$httpClient = (new GuzzleHttpClientFactory($this->maxRetries, $this->logger))->create($options); | ||
$httpFactory = new HttpFactory(); | ||
|
||
$serializer = new SmartSerializer(); | ||
|
||
$requestFactory = new RequestFactory( | ||
$httpFactory, | ||
$httpFactory, | ||
$httpFactory, | ||
$serializer, | ||
); | ||
|
||
$transport = (new TransportFactory()) | ||
->setHttpClient($httpClient) | ||
->setRequestFactory($requestFactory) | ||
->create(); | ||
|
||
return new Client($transport, new EndpointFactory($serializer), []); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace OpenSearch; | ||
|
||
use OpenSearch\HttpClient\SymfonyHttpClientFactory; | ||
use OpenSearch\Serializers\SmartSerializer; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* Creates an OpenSearch client using Symfony HTTP Client. | ||
*/ | ||
class SymfonyClientFactory implements ClientFactoryInterface | ||
{ | ||
public function __construct( | ||
protected int $maxRetries = 0, | ||
protected ?LoggerInterface $logger = null, | ||
) { | ||
} | ||
|
||
/** | ||
* Creates a new OpenSearch client using Symfony HTTP Client. | ||
* | ||
* @param array<string,mixed> $options | ||
* The Symfony HTTP Client options. | ||
*/ | ||
public function create(array $options): Client | ||
{ | ||
$httpClient = (new SymfonyHttpClientFactory($this->maxRetries, $this->logger))->create($options); | ||
|
||
$serializer = new SmartSerializer(); | ||
|
||
$requestFactory = new RequestFactory( | ||
$httpClient, | ||
$httpClient, | ||
$httpClient, | ||
$serializer, | ||
); | ||
|
||
$transport = (new TransportFactory()) | ||
->setHttpClient($httpClient) | ||
->setRequestFactory($requestFactory) | ||
->create(); | ||
|
||
$endpointFactory = new EndpointFactory(); | ||
return new Client($transport, $endpointFactory, []); | ||
} | ||
} |
Oops, something went wrong.