Skip to content

Support Guzzle 7+ #175

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 10 commits into from
Jul 2, 2020
Merged
Changes from 6 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
28 changes: 19 additions & 9 deletions src/Strategy/CommonClassesStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Http\Message\StreamFactory\SlimStreamFactory;
use Http\Message\UriFactory\SlimUriFactory;
use Slim\Http\Request as SlimRequest;
use GuzzleHttp\Client as GuzzleHttp;
use Http\Adapter\Guzzle6\Client as Guzzle6;
use Http\Adapter\Guzzle5\Client as Guzzle5;
use Http\Client\Curl\Client as Curl;
Expand Down Expand Up @@ -95,6 +96,10 @@ final class CommonClassesStrategy implements DiscoveryStrategy
'class' => [self::class, 'symfonyPsr18Instantiate'],
'condition' => [SymfonyPsr18::class, Psr17RequestFactory::class],
],
[
'class' => GuzzleHttp::class,
'condition' => GuzzleHttp::class,
],
[
'class' => [self::class, 'buzzInstantiate'],
'condition' => [\Buzz\Client\FileGetContents::class, \Buzz\Message\ResponseBuilder::class],
Expand All @@ -107,9 +112,20 @@ final class CommonClassesStrategy implements DiscoveryStrategy
*/
public static function getCandidates($type)
{
if (Psr18Client::class === $type) {
$candidates = self::$classes[PSR18Client::class];
$candidates = [];

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we need this.

This logic should be on the condition

$candidates[] = $c;
}
} else {
$candidates[] = $c;
}
}

if (Psr18Client::class === $type) {
// HTTPlug 2.0 clients implements PSR18Client too.
foreach (self::$classes[HttpClient::class] as $c) {
try {
Expand All @@ -120,15 +136,9 @@ public static function getCandidates($type)
trigger_error(sprintf('Got exception "%s (%s)" while checking if a PSR-18 Client is available', get_class($e), $e->getMessage()), E_USER_WARNING);
}
}

return $candidates;
}

if (isset(self::$classes[$type])) {
return self::$classes[$type];
}

return [];
return $candidates;
}

public static function buzzInstantiate()
Expand Down