From 9ff61d34c1b4730e8d43ea9dc837f1a32af893f1 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 11 Nov 2021 09:08:38 +0100 Subject: [PATCH] symfony httplug adapter needs php-http httplug to be installed if we don't check for the httplug client interface, we trigger a warning: https://github.com/symfony/http-client/blob/290eb481973b4984eb59377585f6afbc65a0f645/HttplugClient.php#L44 --- src/Psr18ClientDiscovery.php | 2 +- src/Strategy/CommonClassesStrategy.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Psr18ClientDiscovery.php b/src/Psr18ClientDiscovery.php index 7fcdb17..dfd2dd1 100644 --- a/src/Psr18ClientDiscovery.php +++ b/src/Psr18ClientDiscovery.php @@ -24,7 +24,7 @@ public static function find() try { $client = static::findOneByType(ClientInterface::class); } catch (DiscoveryFailedException $e) { - throw new \Http\Discovery\Exception\NotFoundException('No PSR-18 clients found. Make sure to install a package providing "psr/http-client-implementation". Example: "php-http/guzzle6-adapter".', 0, $e); + throw new \Http\Discovery\Exception\NotFoundException('No PSR-18 clients found. Make sure to install a package providing "psr/http-client-implementation". Example: "php-http/guzzle7-adapter".', 0, $e); } return static::instantiateClass($client); diff --git a/src/Strategy/CommonClassesStrategy.php b/src/Strategy/CommonClassesStrategy.php index b950e96..8bddbe8 100644 --- a/src/Strategy/CommonClassesStrategy.php +++ b/src/Strategy/CommonClassesStrategy.php @@ -17,6 +17,7 @@ use Http\Client\HttpAsyncClient; use Http\Client\HttpClient; use Http\Client\Socket\Client as Socket; +use Http\Discovery\ClassDiscovery; use Http\Discovery\Exception\NotFoundException; use Http\Discovery\MessageFactoryDiscovery; use Http\Discovery\Psr17FactoryDiscovery; @@ -136,8 +137,11 @@ private static function getPsr18Candidates() // HTTPlug 2.0 clients implements PSR18Client too. foreach (self::$classes[HttpClient::class] as $c) { + if (!is_string($c['class'])) { + continue; + } try { - if (is_subclass_of($c['class'], Psr18Client::class)) { + if (ClassDiscovery::safeClassExists($c['class']) && is_subclass_of($c['class'], Psr18Client::class)) { $candidates[] = $c; } } catch (\Throwable $e) {