Skip to content

Commit

Permalink
Refactor to remove "guzzle specific" logic (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm authored Jul 2, 2020
1 parent fef8475 commit a6bce7a
Showing 1 changed file with 7 additions and 13 deletions.
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

0 comments on commit a6bce7a

Please sign in to comment.