1
0

Merge pull request #27 from alessiodionisi/list-command

List command by prefix
This commit is contained in:
Ivan Kudinov
2017-04-14 00:35:27 +06:00
committed by GitHub
3 changed files with 115 additions and 10 deletions

View File

@@ -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();

View File

@@ -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
*

View 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);
}
}