From f199c86a28e7899aba28d02a0ad33b301a67eb8c Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Mon, 14 Oct 2024 19:28:45 +0200 Subject: [PATCH] Add Resource::open() method to make URL creation simpler --- README.md | 2 +- src/main/php/com/amazon/aws/api/Resource.class.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cf094db..399ca74 100755 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ $file= new File('large.txt'); $file->open(File::READ); try { - $transfer= $s3->open('PUT', 'target/'.$file->filename, [ + $transfer= $s3->resource('target/{0}', [$file->filename])->open('PUT', [ 'x-amz-content-sha256' => SignatureV4::UNSIGNED, // Or calculate from file 'Content-Type' => 'text/plain', 'Content-Length' => $file->size(), diff --git a/src/main/php/com/amazon/aws/api/Resource.class.php b/src/main/php/com/amazon/aws/api/Resource.class.php index 0d69f0d..61f5580 100755 --- a/src/main/php/com/amazon/aws/api/Resource.class.php +++ b/src/main/php/com/amazon/aws/api/Resource.class.php @@ -74,4 +74,15 @@ public function transmit($payload, $type= 'application/json') { $this->serialize($this->marshalling->marshal($payload), $type) ); } + + /** + * Opens a request and returns a `Transfer` instance for writing data to + * + * @param string $method + * @param [:string] $headers + * @return com.amazon.aws.api.Transfer + */ + public function open(string $method, array $headers) { + return $this->endpoint->open($method, $this->target, $headers); + } } \ No newline at end of file