Skip to content

Instantly share code, notes, and snippets.

@ismail1432
Created February 22, 2023 17:14
Show Gist options
  • Save ismail1432/0f487fc6520ac169a35b5ed4d61dafe6 to your computer and use it in GitHub Desktop.
Save ismail1432/0f487fc6520ac169a35b5ed4d61dafe6 to your computer and use it in GitHub Desktop.
<?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