From da558ecbec7ef3163ce0e2af0fce436b38e77806 Mon Sep 17 00:00:00 2001 From: Alessio Dionisi Date: Thu, 30 Mar 2017 13:05:06 +0200 Subject: [PATCH] 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); + } +}