Skip to content

Commit 3943279

Browse files
authored
avoid weird autoloading side effects for psr 18 clients too (#202)
e.g. symfony httplug adapter triggers a warning if the php-http/httplug is not available https://github.com/symfony/http-client/blob/290eb481973b4984eb59377585f6afbc65a0f645/HttplugClient.php#L44
1 parent 6a53322 commit 3943279

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Psr18ClientDiscovery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static function find()
2424
try {
2525
$client = static::findOneByType(ClientInterface::class);
2626
} catch (DiscoveryFailedException $e) {
27-
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);
27+
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);
2828
}
2929

3030
return static::instantiateClass($client);

src/Strategy/CommonClassesStrategy.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Http\Client\HttpAsyncClient;
1818
use Http\Client\HttpClient;
1919
use Http\Client\Socket\Client as Socket;
20+
use Http\Discovery\ClassDiscovery;
2021
use Http\Discovery\Exception\NotFoundException;
2122
use Http\Discovery\MessageFactoryDiscovery;
2223
use Http\Discovery\Psr17FactoryDiscovery;
@@ -136,8 +137,11 @@ private static function getPsr18Candidates()
136137

137138
// HTTPlug 2.0 clients implements PSR18Client too.
138139
foreach (self::$classes[HttpClient::class] as $c) {
140+
if (!is_string($c['class'])) {
141+
continue;
142+
}
139143
try {
140-
if (is_subclass_of($c['class'], Psr18Client::class)) {
144+
if (ClassDiscovery::safeClassExists($c['class']) && is_subclass_of($c['class'], Psr18Client::class)) {
141145
$candidates[] = $c;
142146
}
143147
} catch (\Throwable $e) {

0 commit comments

Comments
 (0)