diff --git a/.changes/nextrelease/feat_named_args_support.json b/.changes/nextrelease/feat_named_args_support.json new file mode 100644 index 0000000000..eab512be68 --- /dev/null +++ b/.changes/nextrelease/feat_named_args_support.json @@ -0,0 +1,7 @@ +[ + { + "type": "enhancement", + "category": "", + "description": "Add support to named arguments in the AwsClientTrait __call method." + } +] \ No newline at end of file diff --git a/src/AwsClientTrait.php b/src/AwsClientTrait.php index f31a24edc7..ff39534c4b 100644 --- a/src/AwsClientTrait.php +++ b/src/AwsClientTrait.php @@ -75,7 +75,7 @@ public function __call($name, array $args) $name = $this->aliases[ucfirst($name)]; } - $params = isset($args[0]) ? $args[0] : []; + $params = $args['args'] ?? $args[0] ?? []; if (!empty($isAsync)) { return $this->executeAsync( diff --git a/tests/AwsClientTest.php b/tests/AwsClientTest.php index 6523a5cf7f..b459284ebc 100644 --- a/tests/AwsClientTest.php +++ b/tests/AwsClientTest.php @@ -1017,4 +1017,19 @@ public function testAppendsUserAgentMiddleware() ]); $client->listBuckets(); } + + public function testSupportsNamedArgs() + { + $client = new S3Client([ + 'region' => 'us-east-2', + 'handler' => function (CommandInterface $command, RequestInterface $request) { + $this->assertEquals('foo', $command['Bucket']); + + return new Result(); + } + ]); + $client->listObjects(args: [ + 'Bucket' => 'foo', + ]); + } }