Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FrameworkBundle] revert implementing LoggerAwareInterface in HTTP client decorators #54674

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 1 addition & 10 deletions src/Symfony/Component/HttpClient/CachingHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace Symfony\Component\HttpClient;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpClient\Response\MockResponse;
use Symfony\Component\HttpClient\Response\ResponseStream;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -33,7 +31,7 @@
*
* @author Nicolas Grekas <p@tchwork.com>
*/
class CachingHttpClient implements HttpClientInterface, LoggerAwareInterface, ResetInterface
class CachingHttpClient implements HttpClientInterface, ResetInterface
{
use HttpClientTrait;

Expand Down Expand Up @@ -144,11 +142,4 @@ public function reset(): void
$this->client->reset();
}
}

public function setLogger(LoggerInterface $logger): void
{
if ($this->client instanceof LoggerAwareInterface) {
$this->client->setLogger($logger);
}
}
}
11 changes: 1 addition & 10 deletions src/Symfony/Component/HttpClient/EventSourceHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace Symfony\Component\HttpClient;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpClient\Chunk\ServerSentEvent;
use Symfony\Component\HttpClient\Exception\EventSourceException;
use Symfony\Component\HttpClient\Response\AsyncContext;
Expand All @@ -27,7 +25,7 @@
* @author Antoine Bluchet <soyuka@gmail.com>
* @author Nicolas Grekas <p@tchwork.com>
*/
final class EventSourceHttpClient implements HttpClientInterface, LoggerAwareInterface, ResetInterface
final class EventSourceHttpClient implements HttpClientInterface, ResetInterface
{
use AsyncDecoratorTrait, HttpClientTrait {
AsyncDecoratorTrait::withOptions insteadof HttpClientTrait;
Expand Down Expand Up @@ -158,11 +156,4 @@ public function request(string $method, string $url, array $options = []): Respo
}
});
}

public function setLogger(LoggerInterface $logger): void
{
if ($this->client instanceof LoggerAwareInterface) {
$this->client->setLogger($logger);
}
}
}
11 changes: 1 addition & 10 deletions src/Symfony/Component/HttpClient/RetryableHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\HttpClient;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpClient\Response\AsyncContext;
use Symfony\Component\HttpClient\Response\AsyncResponse;
Expand All @@ -28,7 +27,7 @@
*
* @author Jérémy Derussé <jeremy@derusse.com>
*/
class RetryableHttpClient implements HttpClientInterface, LoggerAwareInterface, ResetInterface
class RetryableHttpClient implements HttpClientInterface, ResetInterface
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementing the LoggerAwareInterface when the constructor already receives a logger doesn't look reasonable to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wonder if we shouldn't change the other decorators to let them optionally receive a logger in their constructor too instead of implementing the LoggerAwareInterface

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing so would also allow us to revert the composer.json changes

{
use AsyncDecoratorTrait;

Expand Down Expand Up @@ -164,14 +163,6 @@ public function request(string $method, string $url, array $options = []): Respo
});
}

public function setLogger(LoggerInterface $logger): void
{
$this->logger = $logger;
if ($this->client instanceof LoggerAwareInterface) {
$this->client->setLogger($logger);
}
}

private function getDelayFromHeader(array $headers): ?int
{
if (null !== $after = $headers['retry-after'][0] ?? null) {
Expand Down
11 changes: 1 addition & 10 deletions src/Symfony/Component/HttpClient/ThrottlingHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace Symfony\Component\HttpClient;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\RateLimiter\LimiterInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
Expand All @@ -21,7 +19,7 @@
/**
* Limits the number of requests within a certain period.
*/
class ThrottlingHttpClient implements HttpClientInterface, LoggerAwareInterface, ResetInterface
class ThrottlingHttpClient implements HttpClientInterface, ResetInterface
{
use DecoratorTrait {
reset as private traitReset;
Expand Down Expand Up @@ -50,11 +48,4 @@ public function reset(): void
$this->traitReset();
$this->rateLimiter->reset();
}

public function setLogger(LoggerInterface $logger): void
{
if ($this->client instanceof LoggerAwareInterface) {
$this->client->setLogger($logger);
}
}
}
11 changes: 1 addition & 10 deletions src/Symfony/Component/HttpClient/UriTemplateHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@

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\Service\ResetInterface;

class UriTemplateHttpClient implements HttpClientInterface, LoggerAwareInterface, ResetInterface
class UriTemplateHttpClient implements HttpClientInterface, ResetInterface
{
use DecoratorTrait;

Expand Down Expand Up @@ -64,13 +62,6 @@ public function withOptions(array $options): static
return $clone;
}

public function setLogger(LoggerInterface $logger): void
{
if ($this->client instanceof LoggerAwareInterface) {
$this->client->setLogger($logger);
}
}

/**
* @return \Closure(string $url, array $vars): string
*/
Expand Down