Skip to content

Commit f014874

Browse files
committed
Merge branch '5.1' into master
* 5.1: (25 commits) stop using the deprecated at() PHPUnit matcher fix lowest allowed version of the HTTP client contracts fix lowest allowed version for the PHPUnit bridge fix merge fix merge drop logger mock in favor of using the BufferingLogger catch ValueError thrown on PHP 8 [Yaml Parser] Fix edge cases when parsing multiple documents fix parsing comments not prefixed by a space [Translator] Make sure a null locale is handled properly deal with errors being thrown on PHP 8 loadRoutes shoud receive RoutingPhpFileLoader [Cache] Allow cache tags to be objects implementing __toString() [HttpKernel] Do not override max_redirects option in HttpClientKernel Log notice when no entry point is configured remove superfluous cast [HttpClient] Support for CURLOPT_LOCALPORT. Upgrade PHPUnit to 8.5 (php 7.2) and 9.3 (php >= 7.3). Fixed exception message formatting [FrameworkBundle] Fix error in xsd which prevent to register more than one metadata ...
2 parents 2ebacda + f3608d7 commit f014874

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

CurlHttpClient.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,14 @@ public function request(string $method, string $url, array $options = []): Respo
270270
}
271271

272272
if ($options['bindto']) {
273-
$curlopts[file_exists($options['bindto']) ? \CURLOPT_UNIX_SOCKET_PATH : \CURLOPT_INTERFACE] = $options['bindto'];
273+
if (file_exists($options['bindto'])) {
274+
$curlopts[\CURLOPT_UNIX_SOCKET_PATH] = $options['bindto'];
275+
} elseif (preg_match('/^(.*):(\d+)$/', $options['bindto'], $matches)) {
276+
$curlopts[\CURLOPT_INTERFACE] = $matches[1];
277+
$curlopts[\CURLOPT_LOCALPORT] = $matches[2];
278+
} else {
279+
$curlopts[\CURLOPT_INTERFACE] = $options['bindto'];
280+
}
274281
}
275282

276283
if (0 < $options['max_duration']) {

HttpClientTrait.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ private static function mergeDefaultOptions(array $options, array $defaultOption
198198
continue;
199199
}
200200

201+
if ('auth_ntlm' === $name) {
202+
if (!\extension_loaded('curl')) {
203+
$msg = 'try installing the "curl" extension to use "%s" instead.';
204+
} else {
205+
$msg = 'try using "%s" instead.';
206+
}
207+
208+
throw new InvalidArgumentException(sprintf('Option "auth_ntlm" is not supported by "%s", '.$msg, __CLASS__, CurlHttpClient::class));
209+
}
210+
201211
$alternatives = [];
202212

203213
foreach ($defaultOptions as $key => $v) {
@@ -206,10 +216,6 @@ private static function mergeDefaultOptions(array $options, array $defaultOption
206216
}
207217
}
208218

209-
if ('auth_ntlm' === $name) {
210-
throw new InvalidArgumentException(sprintf('Option "auth_ntlm" is not supported by "%s", try using CurlHttpClient instead.', __CLASS__));
211-
}
212-
213219
throw new InvalidArgumentException(sprintf('Unsupported option "%s" passed to "%s", did you mean "%s"?', $name, __CLASS__, implode('", "', $alternatives ?: array_keys($defaultOptions))));
214220
}
215221

Tests/CurlHttpClientTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ protected function getHttpClient(string $testCase): HttpClientInterface
3535
return new CurlHttpClient(['verify_peer' => false, 'verify_host' => false]);
3636
}
3737

38+
public function testBindToPort()
39+
{
40+
$client = $this->getHttpClient(__FUNCTION__);
41+
$response = $client->request('GET', 'http://localhost:8057', ['bindto' => '127.0.0.1:9876']);
42+
$response->getStatusCode();
43+
44+
$r = new \ReflectionProperty($response, 'handle');
45+
$r->setAccessible(true);
46+
47+
$curlInfo = curl_getinfo($r->getValue($response));
48+
49+
self::assertSame('127.0.0.1', $curlInfo['local_ip']);
50+
self::assertSame(9876, $curlInfo['local_port']);
51+
}
52+
3853
public function testTimeoutIsNotAFatalError()
3954
{
4055
if ('\\' === \DIRECTORY_SEPARATOR) {

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"require": {
2424
"php": ">=7.2.5",
2525
"psr/log": "^1.0",
26-
"symfony/http-client-contracts": "^2.1.3",
26+
"symfony/http-client-contracts": "^2.2",
2727
"symfony/polyfill-php73": "^1.11",
2828
"symfony/polyfill-php80": "^1.15",
2929
"symfony/service-contracts": "^1.0|^2"

0 commit comments

Comments
 (0)