1212
1313namespace Hyperf \Filesystem \Adapter ;
1414
15- use Aws \Handler \GuzzleV6 \GuzzleHandler ;
15+ use Aws \Handler \Guzzle \GuzzleHandler ;
16+ use Aws \Handler \GuzzleV6 \GuzzleHandler as V6GuzzleHandler ;
1617use Aws \S3 \S3Client ;
1718use GuzzleHttp \Client ;
1819use GuzzleHttp \HandlerStack ;
1920use Hyperf \Filesystem \Contract \AdapterFactoryInterface ;
21+ use Hyperf \Filesystem \Exception \InvalidArgumentException ;
2022use Hyperf \Filesystem \Version ;
2123use Hyperf \Guzzle \CoroutineHandler ;
2224use 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