From da558ecbec7ef3163ce0e2af0fce436b38e77806 Mon Sep 17 00:00:00 2001 From: Alessio Dionisi Date: Thu, 30 Mar 2017 13:05:06 +0200 Subject: [PATCH 1/2] list command by prefix --- src/CommandFactory.php | 15 ++++++ src/commands/ListCommand.php | 88 ++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 src/commands/ListCommand.php diff --git a/src/CommandFactory.php b/src/CommandFactory.php index d734591..23f9a1d 100644 --- a/src/CommandFactory.php +++ b/src/CommandFactory.php @@ -10,6 +10,7 @@ use frostealth\yii2\aws\s3\commands\GetUrlCommand; use frostealth\yii2\aws\s3\commands\PutCommand; use frostealth\yii2\aws\s3\commands\RestoreCommand; use frostealth\yii2\aws\s3\commands\UploadCommand; +use frostealth\yii2\aws\s3\commands\ListCommand; use frostealth\yii2\aws\s3\interfaces; /** @@ -119,6 +120,20 @@ class CommandFactory return $command; } + /** + * @param string $prefix + * + * @return \frostealth\yii2\aws\s3\commands\ListCommand + */ + public function list(string $prefix): ListCommand + { + /** @var ListCommand $command */ + $command = $this->builder->build(ListCommand::class); + $command->byPrefix($prefix); + + return $command; + } + /** * @param string $filename * diff --git a/src/commands/ListCommand.php b/src/commands/ListCommand.php new file mode 100644 index 0000000..6a6080e --- /dev/null +++ b/src/commands/ListCommand.php @@ -0,0 +1,88 @@ +args['Bucket'] ?? ''; + } + + /** + * @param string $name + * + * @return $this + */ + public function inBucket(string $name) + { + $this->args['Bucket'] = $name; + + return $this; + } + + /** + * @return string + */ + public function getPrefix(): string + { + return $this->args['Prefix'] ?? ''; + } + + /** + * @param string $prefix + * + * @return $this + */ + public function byPrefix(string $prefix) + { + $this->args['Prefix'] = $prefix; + + return $this; + } + + /** + * @internal used by the handlers + * + * @return string + */ + public function getName(): string + { + return 'ListObjects'; + } + + /** + * @internal used by the handlers + * + * @return array + */ + public function toArgs(): array + { + return array_replace($this->options, $this->args); + } +} From 275d8ca49bc2da16bd218d6f6757afc6d0a8f7ed Mon Sep 17 00:00:00 2001 From: Alessio Dionisi Date: Thu, 30 Mar 2017 13:12:19 +0200 Subject: [PATCH 2/2] readme --- README.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 146f089..1d2bf31 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ $result = $s3->commands()->upload('filename.ext', '/path/to/local/file.ext')->wi $result = $s3->commands()->restore('filename.ext', $days = 7)->execute(); +$result = $s3->commands()->list('/path')->execute(); + /** @var bool $exist */ $exist = $s3->commands()->exist('filename.ext')->execute(); @@ -168,11 +170,11 @@ class MyCommand implements Command, HasBucket { return $this->bucket; } - + public function inBucket(string $bucket) { $this->bucket = $bucket; - + return $this; } @@ -240,36 +242,36 @@ use frostealth\yii2\aws\s3\interfaces\commands\PlainCommand; class MyPlainCommand implements PlainCommand, HasBucket { protected $args = []; - + public function getBucket() { return $this->args['Bucket'] ?? ''; } - + public function inBucket(string $bucket) { $this->args['Bucket'] = $bucket; - + return $this; } - + public function getSomething() { return $this->args['something'] ?? ''; } - + public function withSomething($something) { $this->args['something'] = $something; - + return $this; } - + public function getName(): string { return 'AwsS3CommandName'; } - + public function toArgs(): array { return $this->args;