Created
February 22, 2023 17:14
-
-
Save ismail1432/0f487fc6520ac169a35b5ed4d61dafe6 to your computer and use it in GitHub Desktop.
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
<?php | |
namespace App; | |
class BaseHttpClient | |
{ | |
implements HttpClientInterface | |
{ | |
use AsyncDecoratorTrait; | |
public function request(string $method, string $url, array $options = []): ResponseInterface | |
{ | |
return $this->client->request($method, $url, $options); | |
} | |
public function stream(iterable|ResponseInterface $responses, float $timeout = null): ResponseStreamInterface | |
{ | |
return $this->client->stream($responses, $timeout); | |
} | |
} | |
// Kernel.php | |
class Kernel extends BaseKernel implements CompilerPassInterface | |
{ | |
use MicroKernelTrait; | |
public function process(ContainerBuilder $c): void | |
{ | |
$c->register('http_client.base', BaseHttpClient::class); | |
$retryStrategy = new GenericRetryStrategy(/** $conf, can be harcoded or fetched from parameter $c->getParameter('blabla')*/); | |
$c->register('http_client.retryable', RetryableHttpClient::class) | |
->setArguments([new Reference('http_client.base'), $retryStrategy, $maxRetries, new Reference('logger')]) | |
->setDecoratedService('http_client'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment