8000 feature #35273 [HttpClient] Add LoggerAwareInterface to ScopingHttpCl… · symfony/symfony@9edb161 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9edb161

Browse files
committed
feature #35273 [HttpClient] Add LoggerAwareInterface to ScopingHttpClient and TraceableHttpClient (pierredup)
This PR was merged into the 5.1-dev branch. Discussion ---------- [HttpClient] Add LoggerAwareInterface to ScopingHttpClient and TraceableHttpClient | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A This allows changing the logger when using `ScopingHttpClient` (and `TraceableHttpClient` during dev) Commits ------- 1137bdc Add LoggerAwareInterface to ScopingHttpClient and TraceableHttpClient
2 parents af3c205 + 1137bdc commit 9edb161

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/Symfony/Component/HttpClient/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
5.1.0
5+
-----
6+
7+
* added `LoggerAwareInterface` to `ScopingHttpClient` and `TraceableHttpClient`
8+
49
4.4.0
510
-----
611

src/Symfony/Component/HttpClient/ScopingHttpClient.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\HttpClient;
1313

14+
use Psr\Log\LoggerAwareInterface;
15+
use Psr\Log\LoggerInterface;
1416
use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
1517
use Symfony\Contracts\HttpClient\HttpClientInterface;
1618
use Symfony\Contracts\HttpClient\ResponseInterface;
@@ -22,7 +24,7 @@
2224
*
2325
* @author Anthony Martin <anthony.martin@sensiolabs.com>
2426
*/
25-
class ScopingHttpClient implements HttpClientInterface, ResetInterface
27+
class ScopingHttpClient implements HttpClientInterface, ResetInterface, LoggerAwareInterface
2628
{
2729
use HttpClientTrait;
2830

@@ -98,4 +100,14 @@ public function reset()
98100
$this->client->reset();
99101
}
100102
}
103+
104+
/**
105+
* {@inheritdoc}
106+
*/
107+
public function setLogger(LoggerInterface $logger): void
108+
{
109+
if ($this->client instanceof LoggerAwareInterface) {
110+
$this->client->setLogger($logger);
111+
}
112+
}
101113
}

src/Symfony/Component/HttpClient/TraceableHttpClient.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\HttpClient;
1313

14+
use Psr\Log\LoggerAwareInterface;
15+
use Psr\Log\LoggerInterface;
1416
use Symfony\Contracts\HttpClient\HttpClientInterface;
1517
use Symfony\Contracts\HttpClient\ResponseInterface;
1618
u 8000 se Symfony\Contracts\HttpClient\ResponseStreamInterface;
@@ -19,7 +21,7 @@
1921
/**
2022
* @author Jérémy Romey <jeremy@free-agent.fr>
2123
*/
22-
final class TraceableHttpClient implements HttpClientInterface, ResetInterface
24+
final class TraceableHttpClient implements HttpClientInterface, ResetInterface, LoggerAwareInterface
2325
{
2426
private $client;
2527
private $tracedRequests = [];
@@ -75,4 +77,14 @@ public function reset()
7577

7678
$this->tracedRequests = [];
7779
}
80+
81+
/**
82+
* {@inheritdoc}
83+
*/
84+
public function setLogger(LoggerInterface $logger): void
85+
{
86+
if ($this->client instanceof LoggerAwareInterface) {
87+
$this->client->setLogger($logger);
88+
}
89+
}
7890
}

0 commit comments

Comments
 (0)
0