Skip to content

Commit 2304f50

Browse files
Merge branch '5.4' into 6.0
* 5.4: Fix tests on PHP 8.1 [Cache] Fix memory leak [Config] Add missing use statement in generated config builder classes [DependencyInjection] fix inlining when non-shared services are involved [FrameworkBundle] fix deprecation message [DoctrineBridge] add support for the JSON type [PHPUnitBridge] Fix Uncaught ValueError [HttpClient] Implement ResetInterface for all http clients [HttpKernel] allow ignoring kernel.reset methods that don't exist [FrameworkBundle] fix registering late resettable services [Validator] Missing translations for Greek (el) translate for japanese 101,102,103 Use symfony-*-bridge instead of symfony-bridge for component bridges Fix Loco Provider [HttpClient] Curl http client has to reinit curl multi handle on reset [SecurityBundle] Fix compat with symfony/security-core:^6 (ter) [Validator] Add Swedish translation for issue #43737
2 parents c6a3c1e + cf4981d commit 2304f50

13 files changed

+96
-8
lines changed

CachingHttpClient.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Contracts\HttpClient\HttpClientInterface;
2121
use Symfony\Contracts\HttpClient\ResponseInterface;
2222
use Symfony\Contracts\HttpClient\ResponseStreamInterface;
23+
use Symfony\Contracts\Service\ResetInterface;
2324

2425
/**
2526
* Adds caching on top of an HTTP client.
@@ -30,7 +31,7 @@
3031
*
3132
* @author Nicolas Grekas <[email protected]>
3233
*/
33-
class CachingHttpClient implements HttpClientInterface
34+
class CachingHttpClient implements HttpClientInterface, ResetInterface
3435
{
3536
use HttpClientTrait;
3637

@@ -139,4 +140,11 @@ public function stream(ResponseInterface|iterable $responses, float $timeout = n
139140
yield $this->client->stream($clientResponses, $timeout);
140141
})());
141142
}
143+
144+
public function reset()
145+
{
146+
if ($this->client instanceof ResetInterface) {
147+
$this->client->reset();
148+
}
149+
}
142150
}

DecoratorTrait.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Contracts\HttpClient\HttpClientInterface;
1515
use Symfony\Contracts\HttpClient\ResponseInterface;
1616
use Symfony\Contracts\HttpClient\ResponseStreamInterface;
17+
use Symfony\Contracts\Service\ResetInterface;
1718

1819
/**
1920
* Eases with writing decorators.
@@ -55,4 +56,11 @@ public function withOptions(array $options): static
5556

5657
return $clone;
5758
}
59+
60+
public function reset()
61+
{
62+
if ($this->client instanceof ResetInterface) {
63+
$this->client->reset();
64+
}
65+
}
5866
}

EventSourceHttpClient.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
2020
use Symfony\Contracts\HttpClient\HttpClientInterface;
2121
use Symfony\Contracts\HttpClient\ResponseInterface;
22+
use Symfony\Contracts\Service\ResetInterface;
2223

2324
/**
2425
* @author Antoine Bluchet <[email protected]>
2526
* @author Nicolas Grekas <[email protected]>
2627
*/
27-
final class EventSourceHttpClient implements HttpClientInterface
28+
final class EventSourceHttpClient implements HttpClientInterface, ResetInterface
2829
{
2930
use AsyncDecoratorTrait, HttpClientTrait {
3031
AsyncDecoratorTrait::withOptions insteadof HttpClientTrait;

HttplugClient.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
3939
use Symfony\Contracts\HttpClient\HttpClientInterface;
4040
use Symfony\Contracts\HttpClient\ResponseInterface;
41+
use Symfony\Contracts\Service\ResetInterface;
4142

4243
if (!interface_exists(HttplugInterface::class)) {
4344
throw new \LogicException('You cannot use "Symfony\Component\HttpClient\HttplugClient" as the "php-http/httplug" package is not installed. Try running "composer require php-http/httplug".');
@@ -55,7 +56,7 @@
5556
*
5657
* @author Nicolas Grekas <[email protected]>
5758
*/
58-
final class HttplugClient implements HttplugInterface, HttpAsyncClient, RequestFactory, StreamFactory, UriFactory
59+
final class HttplugClient implements HttplugInterface, HttpAsyncClient, RequestFactory, StreamFactory, UriFactory, ResetInterface
5960
{
6061
private HttpClientInterface $client;
6162
private ResponseFactoryInterface $responseFactory;
@@ -236,6 +237,13 @@ public function __destruct()
236237
$this->wait();
237238
}
238239

240+
public function reset()
241+
{
242+
if ($this->client instanceof ResetInterface) {
243+
$this->client->reset();
244+
}
245+
}
246+
239247
private function sendPsr7Request(RequestInterface $request, bool $buffer = null): ResponseInterface
240248
{
241249
try {

Internal/CurlClientState.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public function reset()
6363
curl_setopt($ch, \CURLOPT_VERBOSE, false);
6464
}
6565
}
66+
67+
curl_multi_close($this->handle);
68+
$this->handle = curl_multi_init();
6669
}
6770

6871
public function __sleep(): array

Internal/NativeClientState.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,11 @@ public function __construct()
3333
{
3434
$this->id = random_int(\PHP_INT_MIN, \PHP_INT_MAX);
3535
}
36+
37+
public function reset()
38+
{
39+
$this->responseCount = 0;
40+
$this->dnsCache = [];
41+
$this->hosts = [];
42+
}
3643
}

MockHttpClient.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
use Symfony\Contracts\HttpClient\HttpClientInterface;
1818
use Symfony\Contracts\HttpClient\ResponseInterface;
1919
use Symfony\Contracts\HttpClient\ResponseStreamInterface;
20+
use Symfony\Contracts\Service\ResetInterface;
2021

2122
/**
2223
* A test-friendly HttpClient that doesn't make actual HTTP requests.
2324
*
2425
* @author Nicolas Grekas <[email protected]>
2526
*/
26-
class MockHttpClient implements HttpClientInterface
27+
class MockHttpClient implements HttpClientInterface, ResetInterface
2728
{
2829
use HttpClientTrait;
2930

@@ -113,4 +114,9 @@ public function withOptions(array $options): static
113114

114115
return $clone;
115116
}
117+
118+
public function reset()
119+
{
120+
$this->requestsCount = 0;
121+
}
116122
}

NativeHttpClient.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Contracts\HttpClient\HttpClientInterface;
2222
use Symfony\Contracts\HttpClient\ResponseInterface;
2323
use Symfony\Contracts\HttpClient\ResponseStreamInterface;
24+
use Symfony\Contracts\Service\ResetInterface;
2425

2526
/**
2627
* A portable implementation of the HttpClientInterface contracts based on PHP stream wrappers.
@@ -30,7 +31,7 @@
3031
*
3132
* @author Nicolas Grekas <[email protected]>
3233
*/
33-
final class NativeHttpClient implements HttpClientInterface, LoggerAwareInterface
34+
final class NativeHttpClient implements HttpClientInterface, LoggerAwareInterface, ResetInterface
3435
{
3536
use HttpClientTrait;
3637
use LoggerAwareTrait;
@@ -252,6 +253,11 @@ public function stream(ResponseInterface|iterable $responses, float $timeout = n
252253
return new ResponseStream(NativeResponse::stream($responses, $timeout));
253254
}
254255

256+
public function reset()
257+
{
258+
$this->multi->reset();
259+
}
260+
255261
private static function getBodyAsString($body): string
256262
{
257263
if (\is_resource($body)) {

NoPrivateNetworkHttpClient.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
use Symfony\Contracts\HttpClient\HttpClientInterface;
2020
use Symfony\Contracts\HttpClient\ResponseInterface;
2121
use Symfony\Contracts\HttpClient\ResponseStreamInterface;
22+
use Symfony\Contracts\Service\ResetInterface;
2223

2324
/**
2425
* Decorator that blocks requests to private networks by default.
2526
*
2627
* @author Hallison Boaventura <[email protected]>
2728
*/
28-
final class NoPrivateNetworkHttpClient implements HttpClientInterface, LoggerAwareInterface
29+
final class NoPrivateNetworkHttpClient implements HttpClientInterface, LoggerAwareInterface, ResetInterface
2930
{
3031
use HttpClientTrait;
3132

@@ -117,4 +118,11 @@ public function withOptions(array $options): static
117118

118119
return $clone;
119120
}
121+
122+
public function reset()
123+
{
124+
if ($this->client instanceof ResetInterface) {
125+
$this->client->reset();
126+
}
127+
}
120128
}

Psr18Client.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use Symfony\Component\HttpClient\Response\StreamWrapper;
3232
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
3333
use Symfony\Contracts\HttpClient\HttpClientInterface;
34+
use Symfony\Contracts\Service\ResetInterface;
3435

3536
if (!interface_exists(RequestFactoryInterface::class)) {
3637
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\Psr18Client" as the "psr/http-factory" package is not installed. Try running "composer require nyholm/psr7".');
@@ -49,7 +50,7 @@
4950
*
5051
* @author Nicolas Grekas <[email protected]>
5152
*/
52-
final class Psr18Client implements ClientInterface, RequestFactoryInterface, StreamFactoryInterface, UriFactoryInterface
53+
final class Psr18Client implements ClientInterface, RequestFactoryInterface, StreamFactoryInterface, UriFactoryInterface, ResetInterface
5354
{
5455
private HttpClientInterface $client;
5556
private ResponseFactoryInterface $responseFactory;
@@ -190,6 +191,13 @@ public function createUri(string $uri = ''): UriInterface
190191

191192
throw new \LogicException(sprintf('You cannot use "%s()" as the "nyholm/psr7" package is not installed. Try running "composer require nyholm/psr7".', __METHOD__));
192193
}
194+
195+
public function reset()
196+
{
197+
if ($this->client instanceof ResetInterface) {
198+
$this->client->reset();
199+
}
200+
}
193201
}
194202

195203
/**

0 commit comments

Comments
 (0)