forked from LiveCarta/yii2-aws-s3
refactoring of commands. now they are semantic
This commit is contained in:
22
README.md
22
README.md
@@ -49,11 +49,11 @@ $s3 = Yii::$app->get('s3');
|
||||
/** @var \Aws\ResultInterface $result */
|
||||
$result = $s3->commands()->get('filename.ext')->saveAs('/path/to/local/file.ext')->execute();
|
||||
|
||||
$result = $s3->commands()->put('filename.ext', 'body')->setContentType('text/plain')->execute();
|
||||
$result = $s3->commands()->put('filename.ext', 'body')->withContentType('text/plain')->execute();
|
||||
|
||||
$result = $s3->commands()->delete('filename.ext')->execute();
|
||||
|
||||
$result = $s3->commands()->upload('filename.ext', '/path/to/local/file.ext')->setAcl('private')->execute();
|
||||
$result = $s3->commands()->upload('filename.ext', '/path/to/local/file.ext')->withAcl('private')->execute();
|
||||
|
||||
$result = $s3->commands()->restore('filename.ext', $days = 7)->execute();
|
||||
|
||||
@@ -118,7 +118,7 @@ $s3 = Yii::$app->get('s3');
|
||||
|
||||
/** @var \frostealth\yii2\aws\s3\commands\GetCommand $command */
|
||||
$command = $s3->create(GetCommand::class);
|
||||
$command->setBucket('my-another-bucket')->setFilename('filename.ext')->saveAs('/path/to/local/file.ext');
|
||||
$command->inBucket('my-another-bucket')->byFilename('filename.ext')->saveAs('/path/to/local/file.ext');
|
||||
|
||||
/** @var \Aws\ResultInterface $result */
|
||||
$result = $s3->execute($command);
|
||||
@@ -169,7 +169,7 @@ class MyCommand implements Command, HasBucket
|
||||
return $this->bucket;
|
||||
}
|
||||
|
||||
public function setBucket(string $bucket)
|
||||
public function inBucket(string $bucket)
|
||||
{
|
||||
$this->bucket = $bucket;
|
||||
|
||||
@@ -181,7 +181,7 @@ class MyCommand implements Command, HasBucket
|
||||
return $this->something;
|
||||
}
|
||||
|
||||
public function setSomething(string $something)
|
||||
public function withSomething(string $something)
|
||||
{
|
||||
$this->something = $something;
|
||||
|
||||
@@ -221,7 +221,7 @@ $s3 = Yii::$app->get('s3');
|
||||
|
||||
/** @var \app\components\s3\commands\MyCommand $command */
|
||||
$command = $s3->create(MyCommand::class);
|
||||
$command->setSomething('some value')->setOption('OptionName', 'value');
|
||||
$command->withSomething('some value')->withOption('OptionName', 'value');
|
||||
|
||||
/** @var \Aws\ResultInterface $result */
|
||||
$result = $s3->execute($command);
|
||||
@@ -234,8 +234,8 @@ Custom plain command looks like this:
|
||||
|
||||
namespace app\components\s3\commands;
|
||||
|
||||
use frostealth\yii2\aws\s3\interfaces\HasBucket;
|
||||
use frostealth\yii2\aws\s3\interfaces\PlainCommand;
|
||||
use frostealth\yii2\aws\s3\interfaces\commands\HasBucket;
|
||||
use frostealth\yii2\aws\s3\interfaces\commands\PlainCommand;
|
||||
|
||||
class MyPlainCommand implements PlainCommand, HasBucket
|
||||
{
|
||||
@@ -246,7 +246,7 @@ class MyPlainCommand implements PlainCommand, HasBucket
|
||||
return $this->args['Bucket'] ?? '';
|
||||
}
|
||||
|
||||
public function setBucket(string $bucket)
|
||||
public function inBucket(string $bucket)
|
||||
{
|
||||
$this->args['Bucket'] = $bucket;
|
||||
|
||||
@@ -258,7 +258,7 @@ class MyPlainCommand implements PlainCommand, HasBucket
|
||||
return $this->args['something'] ?? '';
|
||||
}
|
||||
|
||||
public function setSomething($something)
|
||||
public function withSomething($something)
|
||||
{
|
||||
$this->args['something'] = $something;
|
||||
|
||||
@@ -278,7 +278,7 @@ class MyPlainCommand implements PlainCommand, HasBucket
|
||||
```
|
||||
|
||||
Any command can extend the `ExecutableCommand` class or implement the `Executable` interface that will
|
||||
allow to execute this command immediately: `$command->setSomething('some value')->execute();`.
|
||||
allow to execute this command immediately: `$command->withSomething('some value')->execute();`.
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -58,11 +58,11 @@ class CommandBuilder implements interfaces\CommandBuilder
|
||||
protected function prepareCommand(interfaces\commands\Command $command)
|
||||
{
|
||||
if ($command instanceof interfaces\commands\HasBucket) {
|
||||
$command->setBucket($this->bucket);
|
||||
$command->inBucket($this->bucket);
|
||||
}
|
||||
|
||||
if ($command instanceof interfaces\commands\HasAcl) {
|
||||
$command->setAcl($this->acl);
|
||||
$command->withAcl($this->acl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class CommandFactory
|
||||
{
|
||||
/** @var GetCommand $command */
|
||||
$command = $this->builder->build(GetCommand::class);
|
||||
$command->setFilename($filename);
|
||||
$command->byFilename($filename);
|
||||
|
||||
return $command;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ class CommandFactory
|
||||
{
|
||||
/** @var PutCommand $command */
|
||||
$command = $this->builder->build(PutCommand::class);
|
||||
$command->setFilename($filename)->setBody($body);
|
||||
$command->withFilename($filename)->withBody($body);
|
||||
|
||||
return $command;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ class CommandFactory
|
||||
{
|
||||
/** @var DeleteCommand $command */
|
||||
$command = $this->builder->build(DeleteCommand::class);
|
||||
$command->setFilename($filename);
|
||||
$command->byFilename($filename);
|
||||
|
||||
return $command;
|
||||
}
|
||||
@@ -85,7 +85,7 @@ class CommandFactory
|
||||
{
|
||||
/** @var UploadCommand $command */
|
||||
$command = $this->builder->build(UploadCommand::class);
|
||||
$command->setFilename($filename)->setSource($source);
|
||||
$command->withFilename($filename)->withSource($source);
|
||||
|
||||
return $command;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ class CommandFactory
|
||||
{
|
||||
/** @var RestoreCommand $command */
|
||||
$command = $this->builder->build(RestoreCommand::class);
|
||||
$command->setFilename($filename)->setDays($days);
|
||||
$command->byFilename($filename)->withLifetime($days);
|
||||
|
||||
return $command;
|
||||
}
|
||||
@@ -114,7 +114,7 @@ class CommandFactory
|
||||
{
|
||||
/** @var ExistCommand $command */
|
||||
$command = $this->builder->build(ExistCommand::class);
|
||||
$command->setFilename($filename);
|
||||
$command->byFilename($filename);
|
||||
|
||||
return $command;
|
||||
}
|
||||
@@ -128,7 +128,7 @@ class CommandFactory
|
||||
{
|
||||
/** @var GetUrlCommand $command */
|
||||
$command = $this->builder->build(GetUrlCommand::class);
|
||||
$command->setFilename($filename);
|
||||
$command->byFilename($filename);
|
||||
|
||||
return $command;
|
||||
}
|
||||
@@ -143,7 +143,7 @@ class CommandFactory
|
||||
{
|
||||
/** @var GetPresignedUrlCommand $command */
|
||||
$command = $this->builder->build(GetPresignedUrlCommand::class);
|
||||
$command->setFilename($filename)->setExpires($expires);
|
||||
$command->byFilename($filename)->withExpiration($expires);
|
||||
|
||||
return $command;
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@ trait Options
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function setOptions(array $value)
|
||||
final public function withOptions(array $value)
|
||||
{
|
||||
$this->options = $value;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -38,10 +38,10 @@ trait Options
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function setOption(string $name, $value)
|
||||
final public function withOption(string $name, $value)
|
||||
{
|
||||
$this->options[$name] = $value;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,13 +35,13 @@ class DeleteCommand extends ExecutableCommand implements PlainCommand, HasBucket
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $bucket
|
||||
* @param string $name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBucket(string $bucket)
|
||||
public function inBucket(string $name)
|
||||
{
|
||||
$this->args['Bucket'] = $bucket;
|
||||
$this->args['Bucket'] = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -59,7 +59,7 @@ class DeleteCommand extends ExecutableCommand implements PlainCommand, HasBucket
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilename(string $filename)
|
||||
public function byFilename(string $filename)
|
||||
{
|
||||
$this->args['Key'] = $filename;
|
||||
|
||||
@@ -79,7 +79,7 @@ class DeleteCommand extends ExecutableCommand implements PlainCommand, HasBucket
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setVersionId(string $versionId)
|
||||
public function withVersionId(string $versionId)
|
||||
{
|
||||
$this->args['VersionId'] = $versionId;
|
||||
|
||||
@@ -87,6 +87,8 @@ class DeleteCommand extends ExecutableCommand implements PlainCommand, HasBucket
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal used by the handlers
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
@@ -95,6 +97,8 @@ class DeleteCommand extends ExecutableCommand implements PlainCommand, HasBucket
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal used by the handlers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArgs(): array
|
||||
|
||||
@@ -16,7 +16,7 @@ use frostealth\yii2\aws\s3\interfaces\commands\HasBucket;
|
||||
class ExistCommand extends ExecutableCommand implements HasBucket
|
||||
{
|
||||
use Options;
|
||||
|
||||
|
||||
/** @var string */
|
||||
protected $bucket;
|
||||
|
||||
@@ -32,14 +32,14 @@ class ExistCommand extends ExecutableCommand implements HasBucket
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $bucket
|
||||
* @param string $name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBucket(string $bucket)
|
||||
public function inBucket(string $name)
|
||||
{
|
||||
$this->bucket = $bucket;
|
||||
|
||||
$this->bucket = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -56,10 +56,10 @@ class ExistCommand extends ExecutableCommand implements HasBucket
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilename(string $filename)
|
||||
public function byFilename(string $filename)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,13 +35,13 @@ class GetCommand extends ExecutableCommand implements PlainCommand, HasBucket, A
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $bucket
|
||||
* @param string $name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBucket(string $bucket)
|
||||
public function inBucket(string $name)
|
||||
{
|
||||
$this->args['Bucket'] = $bucket;
|
||||
$this->args['Bucket'] = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -59,7 +59,7 @@ class GetCommand extends ExecutableCommand implements PlainCommand, HasBucket, A
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilename(string $filename)
|
||||
public function byFilename(string $filename)
|
||||
{
|
||||
$this->args['Key'] = $filename;
|
||||
|
||||
@@ -86,11 +86,13 @@ class GetCommand extends ExecutableCommand implements PlainCommand, HasBucket, A
|
||||
public function ifMatch(string $ifMatch)
|
||||
{
|
||||
$this->args['IfMatch'] = $ifMatch;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal used by the handlers
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
@@ -99,6 +101,8 @@ class GetCommand extends ExecutableCommand implements PlainCommand, HasBucket, A
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal used by the handlers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArgs(): array
|
||||
|
||||
@@ -18,7 +18,7 @@ class GetPresignedUrlCommand extends ExecutableCommand implements HasBucket
|
||||
protected $args = [];
|
||||
|
||||
/** @var mixed */
|
||||
protected $expires;
|
||||
protected $expiration;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
@@ -29,13 +29,13 @@ class GetPresignedUrlCommand extends ExecutableCommand implements HasBucket
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $bucket
|
||||
* @param string $name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBucket(string $bucket)
|
||||
public function inBucket(string $name)
|
||||
{
|
||||
$this->args['Bucket'] = $bucket;
|
||||
$this->args['Bucket'] = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class GetPresignedUrlCommand extends ExecutableCommand implements HasBucket
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilename(string $filename)
|
||||
public function byFilename(string $filename)
|
||||
{
|
||||
$this->args['Key'] = $filename;
|
||||
|
||||
@@ -63,24 +63,26 @@ class GetPresignedUrlCommand extends ExecutableCommand implements HasBucket
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getExpires()
|
||||
public function getExpiration()
|
||||
{
|
||||
return $this->expires;
|
||||
return $this->expiration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|string|\DateTime $expires
|
||||
* @param int|string|\DateTime $expiration
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpires($expires)
|
||||
public function withExpiration($expiration)
|
||||
{
|
||||
$this->expires = $expires;
|
||||
$this->expiration = $expiration;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal used by the handlers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getArgs(): array
|
||||
|
||||
@@ -29,14 +29,14 @@ class GetUrlCommand extends ExecutableCommand implements HasBucket
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $bucket
|
||||
* @param string $name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBucket(string $bucket)
|
||||
public function inBucket(string $name)
|
||||
{
|
||||
$this->bucket = $bucket;
|
||||
|
||||
$this->bucket = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -53,10 +53,10 @@ class GetUrlCommand extends ExecutableCommand implements HasBucket
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilename(string $filename)
|
||||
public function byFilename(string $filename)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,13 +36,13 @@ class PutCommand extends ExecutableCommand implements PlainCommand, HasBucket, H
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $bucket
|
||||
* @param string $name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBucket(string $bucket)
|
||||
public function inBucket(string $name)
|
||||
{
|
||||
$this->args['Bucket'] = $bucket;
|
||||
$this->args['Bucket'] = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -60,7 +60,7 @@ class PutCommand extends ExecutableCommand implements PlainCommand, HasBucket, H
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilename(string $filename)
|
||||
public function withFilename(string $filename)
|
||||
{
|
||||
$this->args['Key'] = $filename;
|
||||
|
||||
@@ -80,7 +80,7 @@ class PutCommand extends ExecutableCommand implements PlainCommand, HasBucket, H
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAcl(string $acl)
|
||||
public function withAcl(string $acl)
|
||||
{
|
||||
$this->args['ACL'] = $acl;
|
||||
|
||||
@@ -100,7 +100,7 @@ class PutCommand extends ExecutableCommand implements PlainCommand, HasBucket, H
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody($body)
|
||||
public function withBody($body)
|
||||
{
|
||||
$this->args['Body'] = $body;
|
||||
|
||||
@@ -120,7 +120,7 @@ class PutCommand extends ExecutableCommand implements PlainCommand, HasBucket, H
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMetadata(array $metadata)
|
||||
public function withMetadata(array $metadata)
|
||||
{
|
||||
$this->args['Metadata'] = $metadata;
|
||||
|
||||
@@ -140,7 +140,7 @@ class PutCommand extends ExecutableCommand implements PlainCommand, HasBucket, H
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setContentType(string $contentType)
|
||||
public function withContentType(string $contentType)
|
||||
{
|
||||
$this->args['ContentType'] = $contentType;
|
||||
|
||||
@@ -150,7 +150,7 @@ class PutCommand extends ExecutableCommand implements PlainCommand, HasBucket, H
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getExpires()
|
||||
public function getExpiration()
|
||||
{
|
||||
return $this->args['Expires'] ?? null;
|
||||
}
|
||||
@@ -160,7 +160,7 @@ class PutCommand extends ExecutableCommand implements PlainCommand, HasBucket, H
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpires($expires)
|
||||
public function withExpiration($expires)
|
||||
{
|
||||
$this->args['Expires'] = $expires;
|
||||
|
||||
@@ -168,6 +168,8 @@ class PutCommand extends ExecutableCommand implements PlainCommand, HasBucket, H
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal used by the handlers
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
@@ -176,6 +178,8 @@ class PutCommand extends ExecutableCommand implements PlainCommand, HasBucket, H
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal used by the handlers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArgs(): array
|
||||
|
||||
@@ -33,13 +33,13 @@ class RestoreCommand extends ExecutableCommand implements PlainCommand, HasBucke
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $bucket
|
||||
* @param string $name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBucket(string $bucket)
|
||||
public function inBucket(string $name)
|
||||
{
|
||||
$this->args['Bucket'] = $bucket;
|
||||
$this->args['Bucket'] = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class RestoreCommand extends ExecutableCommand implements PlainCommand, HasBucke
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilename(string $filename)
|
||||
public function byFilename(string $filename)
|
||||
{
|
||||
$this->args['Key'] = $filename;
|
||||
|
||||
@@ -67,7 +67,7 @@ class RestoreCommand extends ExecutableCommand implements PlainCommand, HasBucke
|
||||
/**
|
||||
* @return int lifetime of the active copy in days
|
||||
*/
|
||||
public function getDays(): int
|
||||
public function getLifetime(): int
|
||||
{
|
||||
return $this->args['Days'] ?? 0;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ class RestoreCommand extends ExecutableCommand implements PlainCommand, HasBucke
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDays(int $days)
|
||||
public function withLifetime(int $days)
|
||||
{
|
||||
$this->args['Days'] = $days;
|
||||
|
||||
@@ -97,7 +97,7 @@ class RestoreCommand extends ExecutableCommand implements PlainCommand, HasBucke
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setVersionId(string $versionId)
|
||||
public function withVersionId(string $versionId)
|
||||
{
|
||||
$this->args['VersionId'] = $versionId;
|
||||
|
||||
@@ -105,6 +105,8 @@ class RestoreCommand extends ExecutableCommand implements PlainCommand, HasBucke
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal used by the handlers
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
@@ -113,6 +115,8 @@ class RestoreCommand extends ExecutableCommand implements PlainCommand, HasBucke
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal used by the handlers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArgs(): array
|
||||
|
||||
@@ -45,13 +45,13 @@ class UploadCommand extends ExecutableCommand implements HasBucket, HasAcl, Asyn
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $bucket
|
||||
* @param string $name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBucket(string $bucket)
|
||||
public function inBucket(string $name)
|
||||
{
|
||||
$this->bucket = $bucket;
|
||||
$this->bucket = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ class UploadCommand extends ExecutableCommand implements HasBucket, HasAcl, Asyn
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAcl(string $acl)
|
||||
public function withAcl(string $acl)
|
||||
{
|
||||
$this->acl = $acl;
|
||||
|
||||
@@ -89,7 +89,7 @@ class UploadCommand extends ExecutableCommand implements HasBucket, HasAcl, Asyn
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSource($source)
|
||||
public function withSource($source)
|
||||
{
|
||||
$this->source = $source;
|
||||
|
||||
@@ -109,7 +109,7 @@ class UploadCommand extends ExecutableCommand implements HasBucket, HasAcl, Asyn
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilename(string $filename)
|
||||
public function withFilename(string $filename)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
|
||||
@@ -129,7 +129,7 @@ class UploadCommand extends ExecutableCommand implements HasBucket, HasAcl, Asyn
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPartSize(int $partSize)
|
||||
public function withPartSize(int $partSize)
|
||||
{
|
||||
$this->options['part_size'] = $partSize;
|
||||
|
||||
@@ -149,7 +149,7 @@ class UploadCommand extends ExecutableCommand implements HasBucket, HasAcl, Asyn
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setConcurrency(int $concurrency)
|
||||
public function withConcurrency(int $concurrency)
|
||||
{
|
||||
$this->options['concurrency'] = $concurrency;
|
||||
|
||||
@@ -169,7 +169,7 @@ class UploadCommand extends ExecutableCommand implements HasBucket, HasAcl, Asyn
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMupThreshold(int $mupThreshold)
|
||||
public function withMupThreshold(int $mupThreshold)
|
||||
{
|
||||
$this->options['mup_threshold'] = $mupThreshold;
|
||||
|
||||
@@ -189,11 +189,9 @@ class UploadCommand extends ExecutableCommand implements HasBucket, HasAcl, Asyn
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setContentType(string $contentType)
|
||||
public function withContentType(string $contentType)
|
||||
{
|
||||
$this->setParam('ContentType', $contentType);
|
||||
|
||||
return $this;
|
||||
return $this->withParam('ContentType', $contentType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,37 +207,35 @@ class UploadCommand extends ExecutableCommand implements HasBucket, HasAcl, Asyn
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setContentDisposition(string $contentDisposition)
|
||||
public function withContentDisposition(string $contentDisposition)
|
||||
{
|
||||
$this->setParam('ContentDisposition', $contentDisposition);
|
||||
return $this->withParam('ContentDisposition', $contentDisposition);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParam(string $name, $default = null)
|
||||
{
|
||||
return $this->options['params'][$name] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withParam(string $name, $value)
|
||||
{
|
||||
$this->options['params'][$name] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getParams(): array
|
||||
{
|
||||
return $this->options['params'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
*/
|
||||
public function setParams(array $params)
|
||||
{
|
||||
$this->options['params'] = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions(): array
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $beforeUpload
|
||||
*
|
||||
@@ -253,22 +249,12 @@ class UploadCommand extends ExecutableCommand implements HasBucket, HasAcl, Asyn
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $default
|
||||
* @internal used by the handlers
|
||||
*
|
||||
* @return mixed
|
||||
* @return array
|
||||
*/
|
||||
protected function getParam(string $name, $default)
|
||||
public function getOptions(): array
|
||||
{
|
||||
return $this->options['params'][$name] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function setParam(string $name, $value)
|
||||
{
|
||||
$this->options['params'][$name] = $value;
|
||||
return $this->options;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ final class GetPresignedUrlCommandHandler extends Handler
|
||||
public function handle(GetPresignedUrlCommand $command): string
|
||||
{
|
||||
$awsCommand = $this->s3Client->getCommand('GetObject', $command->getArgs());
|
||||
$request = $this->s3Client->createPresignedRequest($awsCommand, $command->getExpires());
|
||||
$request = $this->s3Client->createPresignedRequest($awsCommand, $command->getExpiration());
|
||||
|
||||
return (string)$request->getUri();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ final class PlainCommandHandler extends Handler
|
||||
*/
|
||||
public function handle(PlainCommand $command)
|
||||
{
|
||||
$awsCommand = $this->toAwsCommand($command);
|
||||
$awsCommand = $this->transformToAwsCommand($command);
|
||||
|
||||
/** @var \GuzzleHttp\Promise\PromiseInterface $promise */
|
||||
$promise = $this->s3Client->executeAsync($awsCommand);
|
||||
@@ -44,7 +44,7 @@ final class PlainCommandHandler extends Handler
|
||||
*
|
||||
* @return \Aws\CommandInterface
|
||||
*/
|
||||
protected function toAwsCommand(PlainCommand $command): AwsCommand
|
||||
protected function transformToAwsCommand(PlainCommand $command): AwsCommand
|
||||
{
|
||||
$args = array_filter($command->toArgs());
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@ final class UploadCommandHandler extends Handler
|
||||
*/
|
||||
public function handle(UploadCommand $command)
|
||||
{
|
||||
$source = $this->toStream($command->getSource());
|
||||
$source = $this->sourceToStream($command->getSource());
|
||||
$options = array_filter($command->getOptions());
|
||||
|
||||
|
||||
$promise = $this->s3Client->uploadAsync(
|
||||
$command->getBucket(),
|
||||
$command->getFilename(),
|
||||
@@ -31,7 +31,7 @@ final class UploadCommandHandler extends Handler
|
||||
$command->getAcl(),
|
||||
$options
|
||||
);
|
||||
|
||||
|
||||
return $command->isAsync() ? $promise : $promise->wait();
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ final class UploadCommandHandler extends Handler
|
||||
*
|
||||
* @return StreamInterface
|
||||
*/
|
||||
protected function toStream($source): StreamInterface
|
||||
protected function sourceToStream($source): StreamInterface
|
||||
{
|
||||
if (is_string($source)) {
|
||||
$source = Psr7\try_fopen($source, 'r+');
|
||||
|
||||
@@ -12,5 +12,5 @@ interface HasAcl
|
||||
/**
|
||||
* @param string $acl
|
||||
*/
|
||||
public function setAcl(string $acl);
|
||||
public function withAcl(string $acl);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace frostealth\yii2\aws\s3\interfaces\commands;
|
||||
interface HasBucket
|
||||
{
|
||||
/**
|
||||
* @param string $bucket
|
||||
* @param string $name
|
||||
*/
|
||||
public function setBucket(string $bucket);
|
||||
public function inBucket(string $name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user