From c63379edaad8af790be9e3bbd3d40d4eaae4e30c Mon Sep 17 00:00:00 2001 From: Alexey Shokov Date: Thu, 12 Dec 2019 11:41:39 +0400 Subject: [PATCH 1/6] Better defaults for PHP installations with old ICU lib --- docs/request-options.rst | 2 +- src/Client.php | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/request-options.rst b/docs/request-options.rst index 2a477aee9..4e5117b60 100644 --- a/docs/request-options.rst +++ b/docs/request-options.rst @@ -561,7 +561,7 @@ idn_conversion :Types: - bool - int -:Default: ``true`` if ``intl`` extension is available, ``false`` otherwise +:Default: ``true`` if ``intl`` extension is available (and ICU library is 4.6+ for PHP 7.2+), ``false`` otherwise :Constant: ``GuzzleHttp\RequestOptions::IDN_CONVERSION`` .. code-block:: php diff --git a/src/Client.php b/src/Client.php index db4062f94..a9c851cf5 100644 --- a/src/Client.php +++ b/src/Client.php @@ -218,7 +218,8 @@ private function buildUri($uri, array $config) if ($uri->getHost() && isset($config['idn_conversion']) && ($config['idn_conversion'] !== false)) { $idnOptions = ($config['idn_conversion'] === true) ? IDNA_DEFAULT : $config['idn_conversion']; - $asciiHost = idn_to_ascii($uri->getHost(), $idnOptions, INTL_IDNA_VARIANT_UTS46, $info); + $idnaVariant = defined('INTL_IDNA_VARIANT_UTS46') ? INTL_IDNA_VARIANT_UTS46 : 0; + $asciiHost = idn_to_ascii($uri->getHost(), $idnOptions, $idnaVariant, $info); if ($asciiHost === false) { $errorBitSet = isset($info['errors']) ? $info['errors'] : 0; @@ -267,7 +268,14 @@ private function configureDefaults(array $config) ]; // idn_to_ascii() is a part of ext-intl and might be not available - $defaults['idn_conversion'] = function_exists('idn_to_ascii'); + $defaults['idn_conversion'] = function_exists('idn_to_ascii') + // Old ICU versions don't have this constant, so we are basically stuck (see https://github.com/guzzle/guzzle/pull/2424 + // and https://github.com/guzzle/guzzle/issues/2448 for details) + && ( + defined('INTL_IDNA_VARIANT_UTS46') + || + version_compare(PHP_VERSION, '7.2.0') < 0 + ); // Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set. From 6a8a624477bb92c80f47ad5ca72a687b1b855ac4 Mon Sep 17 00:00:00 2001 From: Alexey Shokov Date: Thu, 12 Dec 2019 21:05:07 +0400 Subject: [PATCH 2/6] Faster PHP version comparison Co-Authored-By: Brandon Kelly --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index a9c851cf5..687358ed9 100644 --- a/src/Client.php +++ b/src/Client.php @@ -274,7 +274,7 @@ private function configureDefaults(array $config) && ( defined('INTL_IDNA_VARIANT_UTS46') || - version_compare(PHP_VERSION, '7.2.0') < 0 + PHP_VERSION_ID < 70200 ); // Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set. From 4703d969ea3f9c17a691a66012a591797a9a8944 Mon Sep 17 00:00:00 2001 From: Jaik Dean Date: Mon, 16 Dec 2019 13:39:11 +0000 Subject: [PATCH 3/6] Fix return type for GuzzleHttp\Pool::promise() --- phpstan-baseline.neon | 15 --------------- src/Pool.php | 3 ++- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 13a72f649..f4bd742f2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1125,16 +1125,6 @@ parameters: count: 1 path: src/Pool.php - - - message: "#^Return typehint of method GuzzleHttp\\\\Pool\\:\\:promise\\(\\) has invalid type GuzzleHttp\\\\GuzzleHttp\\\\Promise\\\\Promise\\.$#" - count: 1 - path: src/Pool.php - - - - message: "#^Method GuzzleHttp\\\\Pool\\:\\:promise\\(\\) should return GuzzleHttp\\\\GuzzleHttp\\\\Promise\\\\Promise but returns GuzzleHttp\\\\Promise\\\\PromiseInterface\\.$#" - count: 1 - path: src/Pool.php - - message: "#^Method GuzzleHttp\\\\Pool\\:\\:batch\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" count: 1 @@ -1155,11 +1145,6 @@ parameters: count: 1 path: src/Pool.php - - - message: "#^Call to method wait\\(\\) on an unknown class GuzzleHttp\\\\GuzzleHttp\\\\Promise\\\\Promise\\.$#" - count: 1 - path: src/Pool.php - - message: "#^Method GuzzleHttp\\\\Pool\\:\\:cmpCallback\\(\\) has parameter \\$name with no typehint specified\\.$#" count: 1 diff --git a/src/Pool.php b/src/Pool.php index ec7df6c0e..b921b6264 100644 --- a/src/Pool.php +++ b/src/Pool.php @@ -71,7 +71,8 @@ public function __construct( /** * Get promise - * @return GuzzleHttp\Promise\Promise + * + * @return \GuzzleHttp\Promise\PromiseInterface */ public function promise() { From b751abd9468196ae8504dfec66100bef273a25e9 Mon Sep 17 00:00:00 2001 From: Jaik Dean Date: Mon, 16 Dec 2019 14:45:18 +0000 Subject: [PATCH 4/6] Add use statements for PromiseInterface returns --- src/Client.php | 4 ++-- src/Pool.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index db4062f94..09ecf24d9 100644 --- a/src/Client.php +++ b/src/Client.php @@ -102,7 +102,7 @@ public function __call($method, $args) * @param array $options Request options to apply to the given * request and to the transfer. See \GuzzleHttp\RequestOptions. * - * @return PromiseInterface + * @return Promise\PromiseInterface */ public function sendAsync(RequestInterface $request, array $options = []) { @@ -142,7 +142,7 @@ public function send(RequestInterface $request, array $options = []) * @param string|UriInterface $uri URI object or string. * @param array $options Request options to apply. See \GuzzleHttp\RequestOptions. * - * @return PromiseInterface + * @return Promise\PromiseInterface */ public function requestAsync($method, $uri = '', array $options = []) { diff --git a/src/Pool.php b/src/Pool.php index b921b6264..5838db4f4 100644 --- a/src/Pool.php +++ b/src/Pool.php @@ -2,6 +2,7 @@ namespace GuzzleHttp; use GuzzleHttp\Promise\EachPromise; +use GuzzleHttp\Promise\PromiseInterface; use GuzzleHttp\Promise\PromisorInterface; use Psr\Http\Message\RequestInterface; @@ -72,7 +73,7 @@ public function __construct( /** * Get promise * - * @return \GuzzleHttp\Promise\PromiseInterface + * @return PromiseInterface */ public function promise() { From 62881ec7dcf7f0845b25debd4dd31ba98fdc1da9 Mon Sep 17 00:00:00 2001 From: Jaik Dean Date: Mon, 16 Dec 2019 14:49:41 +0000 Subject: [PATCH 5/6] Update phpstan baseline --- phpstan-baseline.neon | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f4bd742f2..37dbf1bb3 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -16,7 +16,7 @@ parameters: path: src/Client.php - - message: "#^Method GuzzleHttp\\\\Client\\:\\:__call\\(\\) should return GuzzleHttp\\\\Promise\\\\PromiseInterface but returns GuzzleHttp\\\\PromiseInterface\\|Psr\\\\Http\\\\Message\\\\ResponseInterface\\.$#" + message: "#^Method GuzzleHttp\\\\Client\\:\\:__call\\(\\) should return GuzzleHttp\\\\Promise\\\\PromiseInterface but returns GuzzleHttp\\\\Promise\\\\PromiseInterface\\|Psr\\\\Http\\\\Message\\\\ResponseInterface\\.$#" count: 1 path: src/Client.php @@ -25,16 +25,6 @@ parameters: count: 1 path: src/Client.php - - - message: "#^Return typehint of method GuzzleHttp\\\\Client\\:\\:sendAsync\\(\\) has invalid type GuzzleHttp\\\\PromiseInterface\\.$#" - count: 1 - path: src/Client.php - - - - message: "#^Method GuzzleHttp\\\\Client\\:\\:sendAsync\\(\\) should return GuzzleHttp\\\\PromiseInterface but returns GuzzleHttp\\\\Promise\\\\PromiseInterface\\.$#" - count: 1 - path: src/Client.php - - message: "#^Method GuzzleHttp\\\\Client\\:\\:send\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" count: 1 @@ -45,26 +35,11 @@ parameters: count: 2 path: src/Client.php - - - message: "#^Call to method wait\\(\\) on an unknown class GuzzleHttp\\\\PromiseInterface\\.$#" - count: 2 - path: src/Client.php - - message: "#^Method GuzzleHttp\\\\Client\\:\\:requestAsync\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" count: 1 path: src/Client.php - - - message: "#^Return typehint of method GuzzleHttp\\\\Client\\:\\:requestAsync\\(\\) has invalid type GuzzleHttp\\\\PromiseInterface\\.$#" - count: 1 - path: src/Client.php - - - - message: "#^Method GuzzleHttp\\\\Client\\:\\:requestAsync\\(\\) should return GuzzleHttp\\\\PromiseInterface but returns GuzzleHttp\\\\Promise\\\\PromiseInterface\\.$#" - count: 1 - path: src/Client.php - - message: "#^Method GuzzleHttp\\\\Client\\:\\:request\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" count: 1 From b372406562bd7c2dba7dd828ba9987e8d7536fd4 Mon Sep 17 00:00:00 2001 From: Jonny Nott Date: Tue, 17 Dec 2019 08:34:44 +0000 Subject: [PATCH 6/6] fix dash underline for idn_conversion ...so it actually shows up as a section in the docfile --- docs/request-options.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/request-options.rst b/docs/request-options.rst index 2a477aee9..654f7524f 100644 --- a/docs/request-options.rst +++ b/docs/request-options.rst @@ -554,7 +554,7 @@ http_errors idn_conversion ---- +-------------- :Summary: Internationalized Domain Name (IDN) support (enabled by default if ``intl`` extension is available).