Skip to content

Refactor to remove "guzzle specific" logic #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 2, 2020
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