From 1137bdc3f7f6a625f00d083e5af4f713e97253e3 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Thu, 9 Jan 2020 09:05:19 +0200 Subject: [PATCH] Add LoggerAwareInterface to ScopingHttpClient and TraceableHttpClient --- src/Symfony/Component/HttpClient/CHANGELOG.md | 5 +++++ .../Component/HttpClient/ScopingHttpClient.php | 14 +++++++++++++- .../Component/HttpClient/TraceableHttpClient.php | 14 +++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpClient/CHANGELOG.md b/src/Symfony/Component/HttpClient/CHANGELOG.md index 95b6b10d88..6511674206 100644 --- a/src/Symfony/Component/HttpClient/CHANGELOG.md +++ b/src/Symfony/Component/HttpClient/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +5.1.0 +----- + +* added `LoggerAwareInterface` to `ScopingHttpClient` and `TraceableHttpClient` + 4.4.0 ----- diff --git a/src/Symfony/Component/HttpClient/ScopingHttpClient.php b/src/Symfony/Component/HttpClient/ScopingHttpClient.php index a55d011953..66dcccf0e9 100644 --- a/src/Symfony/Component/HttpClient/ScopingHttpClient.php +++ b/src/Symfony/Component/HttpClient/ScopingHttpClient.php @@ -11,6 +11,8 @@ namespace Symfony\Component\HttpClient; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerInterface; use Symfony\Component\HttpClient\Exception\InvalidArgumentException; use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\ResponseInterface; @@ -22,7 +24,7 @@ use Symfony\Contracts\Service\ResetInterface; * * @author Anthony Martin */ -class ScopingHttpClient implements HttpClientInterface, ResetInterface +class ScopingHttpClient implements HttpClientInterface, ResetInterface, LoggerAwareInterface { use HttpClientTrait; @@ -98,4 +100,14 @@ class ScopingHttpClient implements HttpClientInterface, ResetInterface $this->client->reset(); } } + + /** + * {@inheritdoc} + */ + public function setLogger(LoggerInterface $logger): void + { + if ($this->client instanceof LoggerAwareInterface) { + $this->client->setLogger($logger); + } + } } diff --git a/src/Symfony/Component/HttpClient/TraceableHttpClient.php b/src/Symfony/Component/HttpClient/TraceableHttpClient.php index d60d0849cd..4d2e4830bc 100644 --- a/src/Symfony/Component/HttpClient/TraceableHttpClient.php +++ b/src/Symfony/Component/HttpClient/TraceableHttpClient.php @@ -11,6 +11,8 @@ namespace Symfony\Component\HttpClient; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\ResponseInterface; use Symfony\Contracts\HttpClient\ResponseStreamInterface; @@ -19,7 +21,7 @@ use Symfony\Contracts\Service\ResetInterface; /** * @author Jérémy Romey */ -final class TraceableHttpClient implements HttpClientInterface, ResetInterface +final class TraceableHttpClient implements HttpClientInterface, ResetInterface, LoggerAwareInterface { private $client; private $tracedRequests = []; @@ -75,4 +77,14 @@ final class TraceableHttpClient implements HttpClientInterface, ResetInterface $this->tracedRequests = []; } + + /** + * {@inheritdoc} + */ + public function setLogger(LoggerInterface $logger): void + { + if ($this->client instanceof LoggerAwareInterface) { + $this->client->setLogger($logger); + } + } }