forked from LiveCarta/yii2-aws-s3
list command by prefix
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
88
src/commands/ListCommand.php
Normal file
88
src/commands/ListCommand.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace frostealth\yii2\aws\s3\commands;
|
||||
|
||||
use Aws\ResultInterface;
|
||||
use frostealth\yii2\aws\s3\base\commands\ExecutableCommand;
|
||||
use frostealth\yii2\aws\s3\base\commands\traits\Async;
|
||||
use frostealth\yii2\aws\s3\base\commands\traits\Options;
|
||||
use frostealth\yii2\aws\s3\interfaces\commands\Asynchronous;
|
||||
use frostealth\yii2\aws\s3\interfaces\commands\HasBucket;
|
||||
use frostealth\yii2\aws\s3\interfaces\commands\PlainCommand;
|
||||
use GuzzleHttp\Promise\PromiseInterface;
|
||||
|
||||
/**
|
||||
* Class ListCommand
|
||||
*
|
||||
* @method ResultInterface|PromiseInterface execute()
|
||||
*
|
||||
* @package frostealth\yii2\aws\s3\commands
|
||||
*/
|
||||
class ListCommand extends ExecutableCommand implements PlainCommand, HasBucket, Asynchronous
|
||||
{
|
||||
use Async;
|
||||
use Options;
|
||||
|
||||
/** @var array */
|
||||
protected $args = [];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBucket(): string
|
||||
{
|
||||
return $this->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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user