Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/Strategy/CommonClassesStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ final class CommonClassesStrategy implements DiscoveryStrategy
],
[
'class' => GuzzleHttp::class,
'condition' => GuzzleHttp::class,
'condition' => [self::class, 'isGuzzleImplementingPsr18'],
],
[
'class' => [self::class, 'buzzInstantiate'],
Expand All @@ -125,18 +125,7 @@ public static function getCandidates($type)
*/
private static function getPsr18Candidates()
{
$candidates = [];

// Guzzle 6 does not implement the PSR-18 client interface, but Guzzle 7 does.
foreach (self::$classes[Psr18Client::class] ?? [] as $c) {
if (GuzzleHttp::class === $c['class']) {
if (defined('GuzzleHttp\ClientInterface::MAJOR_VERSION')) {
$candidates[] = $c;
}
} else {
$candidates[] = $c;
}
}
$candidates = self::$classes[Psr18Client::class];

// HTTPlug 2.0 clients implements PSR18Client too.
foreach (self::$classes[HttpClient::class] as $c) {
Expand All @@ -162,6 +151,11 @@ public static function symfonyPsr18Instantiate()
return new SymfonyPsr18(null, Psr17FactoryDiscovery::findResponseFactory(), Psr17FactoryDiscovery::findStreamFactory());
}

public static function isGuzzleImplementingPsr18()
{
return defined('GuzzleHttp\ClientInterface::MAJOR_VERSION');
}

/**
* Can be used as a condition.
*
Expand Down