Skip to content

Commit

Permalink
added params in UploadCommand; close #16
Browse files Browse the repository at this point in the history
  • Loading branch information
frostealth committed Oct 7, 2016
1 parent 7293c62 commit 55fa650
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/commands/UploadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,62 @@ public function setMupThreshold(int $mupThreshold)
return $this;
}

/**
* @return string
*/
public function getContentType(): string
{
return $this->getParam('ContentType', '');
}

/**
* @param string $contentType
*
* @return $this
*/
public function setContentType(string $contentType)
{
$this->setParam('ContentType', $contentType);

return $this;
}

/**
* @return string
*/
public function getContentDisposition(): string
{
return $this->getParam('ContentDisposition', '');
}

/**
* @param string $contentDisposition
*
* @return $this
*/
public function setContentDisposition(string $contentDisposition)
{
$this->setParam('ContentDisposition', $contentDisposition);

return $this;
}

/**
* @return array
*/
public function getParams(): array
{
return $this->options['params'] ?? [];
}

/**
* @param array $params
*/
public function setParams(array $params)
{
$this->options['params'] = $params;

This comment has been minimized.

Copy link
@squio

squio Oct 7, 2016

Any reason this method doesn't return $this; ? - This breaks the fluid interface. Now I have to use the following code:

$cmd = Yii::$app->get('s3')->commands()
    ->upload($pathname, $sourceFile)
    ->setContentType($mimeType);
$cmd->setParams([
        'ContentType' => $mimeType,
        'ContentDisposition' => 'attachment',
    ]);
$res = $cmd->execute();

Instead of the more convenient:

$res = Yii::$app->get('s3')->commands()
    ->upload($pathname, $sourceFile)
    ->setParams([
            'ContentType' => $mimeType,
            'ContentDisposition' => 'attachment',
        ])->setContentType($mimeType)
    ->execute();

This comment has been minimized.

Copy link
@frostealth

frostealth Oct 7, 2016

Author Owner

Oh, right. I've forgotten about it.
You can use setContentType() and setContentDisposition() instead of setParams().

$res = Yii::$app->get('s3')->commands()
            ->upload($path, $file)
            ->setContentType($mimeType)
            ->setContentDisposition('attachment')
            ->execute();

This comment has been minimized.

Copy link
@squio

squio Oct 7, 2016

Even better, thanks!

}

/**
* @return array
*/
Expand All @@ -195,4 +251,24 @@ public function beforeUpload(callable $beforeUpload)

return $this;
}

/**
* @param string $name
* @param mixed $default
*
* @return mixed
*/
protected function getParam(string $name, $default)
{
return $this->options['params'][$name] ?? $default;
}

/**
* @param string $name
* @param mixed $value
*/
protected function setParam(string $name, $value)
{
$this->options['params'][$name] = $value;
}

This comment has been minimized.

Copy link
@squio

squio Oct 7, 2016

Same here, return $this; ???

}

0 comments on commit 55fa650

Please sign in to comment.