Skip to content

Commit bf07117

Browse files
authored
Fixed bug that Aws\Handler\GuzzleV6\GuzzleHandler not found. (#7740)
1 parent 8e517aa commit bf07117

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/Adapter/S3AdapterFactory.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313
namespace Hyperf\Filesystem\Adapter;
1414

15-
use Aws\Handler\GuzzleV6\GuzzleHandler;
15+
use Aws\Handler\Guzzle\GuzzleHandler;
16+
use Aws\Handler\GuzzleV6\GuzzleHandler as V6GuzzleHandler;
1617
use Aws\S3\S3Client;
1718
use GuzzleHttp\Client;
1819
use GuzzleHttp\HandlerStack;
1920
use Hyperf\Filesystem\Contract\AdapterFactoryInterface;
21+
use Hyperf\Filesystem\Exception\InvalidArgumentException;
2022
use Hyperf\Filesystem\Version;
2123
use Hyperf\Guzzle\CoroutineHandler;
2224
use League\Flysystem\AwsS3v3\AwsS3Adapter;
@@ -26,7 +28,15 @@ class S3AdapterFactory implements AdapterFactoryInterface
2628
{
2729
public function make(array $options)
2830
{
29-
$handler = new GuzzleHandler(new Client([
31+
// Compatible with both old and new versions of aws-sdk-php
32+
// GuzzleV6\GuzzleHandler was removed in aws-sdk-php 3.379.0
33+
$handlerClass = match (true) {
34+
class_exists(GuzzleHandler::class) => GuzzleHandler::class,
35+
class_exists(V6GuzzleHandler::class) => V6GuzzleHandler::class,
36+
default => throw new InvalidArgumentException('The default guzzle handler not found.'),
37+
};
38+
39+
$handler = new $handlerClass(new Client([
3040
'handler' => HandlerStack::create(new CoroutineHandler()),
3141
]));
3242
$options = array_merge($options, ['http_handler' => $handler]);

0 commit comments

Comments
 (0)