Skip to content

Commit

Permalink
symfony httplug adapter needs php-http httplug to be installed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dbu committed May 25, 2022
1 parent 6a53322 commit b373504
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Psr18ClientDiscovery.php
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/Strategy/CommonClassesStrategy.php
Expand Up @@ -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;
Expand Down Expand Up @@ -101,7 +102,7 @@ final class CommonClassesStrategy implements DiscoveryStrategy
Psr18Client::class => [
[
'class' => [self::class, 'symfonyPsr18Instantiate'],
'condition' => [SymfonyPsr18::class, Psr17RequestFactory::class],
'condition' => [HttpClient::class, SymfonyPsr18::class, Psr17RequestFactory::class],
],
[
'class' => GuzzleHttp::class,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b373504

Please sign in to comment.