1
0

some improvements

This commit is contained in:
frostealth
2016-04-11 23:21:50 +06:00
parent dad9f20f0a
commit a335185184
6 changed files with 41 additions and 24 deletions

View File

@@ -2,6 +2,8 @@ parameters:
git_dir: . git_dir: .
bin_dir: ./vendor/bin bin_dir: ./vendor/bin
tasks: tasks:
phpcs:
standard: "PSR2"
git_blacklist: git_blacklist:
keywords: keywords:
- "die(" - "die("

View File

@@ -1,13 +1,13 @@
<?php <?php
namespace frostealth\yii2\aws\s3\base; namespace frostealth\yii2\aws\s3;
use frostealth\yii2\aws\s3\interfaces; use frostealth\yii2\aws\s3\interfaces;
/** /**
* Class Bus * Class Bus
* *
* @package frostealth\yii2\aws\s3\base * @package frostealth\yii2\aws\s3
*/ */
class Bus implements interfaces\Bus class Bus implements interfaces\Bus
{ {

View File

@@ -1,13 +1,13 @@
<?php <?php
namespace frostealth\yii2\aws\s3\base; namespace frostealth\yii2\aws\s3;
use frostealth\yii2\aws\s3\interfaces; use frostealth\yii2\aws\s3\interfaces;
/** /**
* Class CommandBuilder * Class CommandBuilder
* *
* @package frostealth\yii2\aws\s3\base * @package frostealth\yii2\aws\s3
*/ */
class CommandBuilder implements interfaces\CommandBuilder class CommandBuilder implements interfaces\CommandBuilder
{ {

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace frostealth\yii2\aws\s3\base; namespace frostealth\yii2\aws\s3;
use frostealth\yii2\aws\s3\commands\DeleteCommand; use frostealth\yii2\aws\s3\commands\DeleteCommand;
use frostealth\yii2\aws\s3\commands\ExistCommand; use frostealth\yii2\aws\s3\commands\ExistCommand;
@@ -15,12 +15,12 @@ use frostealth\yii2\aws\s3\interfaces;
/** /**
* Class CommandFactory * Class CommandFactory
* *
* @package frostealth\yii2\aws\s3\base * @package frostealth\yii2\aws\s3
*/ */
class CommandFactory class CommandFactory
{ {
/** @var \frostealth\yii2\aws\s3\interfaces\CommandBuilder */ /** @var \frostealth\yii2\aws\s3\interfaces\CommandBuilder */
private $builder; protected $builder;
/** /**
* CommandFactory constructor. * CommandFactory constructor.

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace frostealth\yii2\aws\s3\base; namespace frostealth\yii2\aws\s3;
use Aws\S3\S3Client; use Aws\S3\S3Client;
use frostealth\yii2\aws\s3\handlers\PlainCommandHandler; use frostealth\yii2\aws\s3\handlers\PlainCommandHandler;
@@ -11,13 +11,16 @@ use yii\base\Object;
/** /**
* Class HandlerResolver * Class HandlerResolver
* *
* @package frostealth\yii2\aws\s3\base * @package frostealth\yii2\aws\s3
*/ */
class HandlerResolver extends Object implements interfaces\HandlerResolver class HandlerResolver extends Object implements interfaces\HandlerResolver
{ {
/** @var array */ /** @var array */
protected $handlers = []; protected $handlers = [];
/** @var string */
protected $plainCommandHandlerClassName = PlainCommandHandler::class;
/** @var \Aws\S3\S3Client */ /** @var \Aws\S3\S3Client */
protected $s3Client; protected $s3Client;
@@ -50,7 +53,7 @@ class HandlerResolver extends Object implements interfaces\HandlerResolver
} }
if ($command instanceof interfaces\commands\PlainCommand) { if ($command instanceof interfaces\commands\PlainCommand) {
return $this->createHandler(PlainCommandHandler::class); return $this->createHandler($this->plainCommandHandlerClassName);
} }
$handlerClass = $commandClass . 'Handler'; $handlerClass = $commandClass . 'Handler';
@@ -85,6 +88,14 @@ class HandlerResolver extends Object implements interfaces\HandlerResolver
} }
} }
/**
* @param string $className
*/
public function setPlainCommandHandler(string $className)
{
$this->plainCommandHandlerClassName = $className;
}
/** /**
* @param string|array $type * @param string|array $type
* *

View File

@@ -3,7 +3,6 @@
namespace frostealth\yii2\aws\s3; namespace frostealth\yii2\aws\s3;
use Aws\ResultInterface; use Aws\ResultInterface;
use frostealth\yii2\aws\s3\base\CommandFactory;
use frostealth\yii2\aws\s3\interfaces\commands\Command; use frostealth\yii2\aws\s3\interfaces\commands\Command;
use frostealth\yii2\aws\s3\interfaces\HandlerResolver; use frostealth\yii2\aws\s3\interfaces\HandlerResolver;
use frostealth\yii2\aws\s3\interfaces\Service as ServiceInterface; use frostealth\yii2\aws\s3\interfaces\Service as ServiceInterface;
@@ -49,15 +48,6 @@ class Service extends Component implements ServiceInterface
/** @var array */ /** @var array */
private $components = []; private $components = [];
/** @var array */
private $definitions = [
'client' => ['class' => 'Aws\S3\S3Client'],
'resolver' => ['class' => 'frostealth\yii2\aws\s3\base\HandlerResolver'],
'bus' => ['class' => 'frostealth\yii2\aws\s3\base\Bus'],
'builder' => ['class' => 'frostealth\yii2\aws\s3\base\CommandBuilder'],
'factory' => ['class' => 'frostealth\yii2\aws\s3\base\CommandFactory'],
];
/** /**
* Initializes the object. * Initializes the object.
* This method is invoked at the end of the constructor after the object is initialized with the * This method is invoked at the end of the constructor after the object is initialized with the
@@ -66,7 +56,7 @@ class Service extends Component implements ServiceInterface
public function init() public function init()
{ {
if (empty($this->clientConfig['credentials'])) { if (empty($this->clientConfig['credentials'])) {
throw new InvalidConfigException('Credentials is not set.'); throw new InvalidConfigException('Credentials are not set.');
} }
if (empty($this->clientConfig['region'])) { if (empty($this->clientConfig['region'])) {
@@ -77,7 +67,7 @@ class Service extends Component implements ServiceInterface
throw new InvalidConfigException('Default bucket name is not set.'); throw new InvalidConfigException('Default bucket name is not set.');
} }
foreach ($this->definitions as $name => $definition) { foreach ($this->defaultComponentDefinitions() as $name => $definition) {
$this->components[$name] = $this->components[$name] ?? $definition; $this->components[$name] = $this->components[$name] ?? $definition;
} }
} }
@@ -109,7 +99,7 @@ class Service extends Component implements ServiceInterface
/** /**
* Returns command factory. * Returns command factory.
* *
* @return \frostealth\yii2\aws\s3\base\CommandFactory * @return \frostealth\yii2\aws\s3\CommandFactory
*/ */
public function commands(): CommandFactory public function commands(): CommandFactory
{ {
@@ -221,7 +211,7 @@ class Service extends Component implements ServiceInterface
{ {
if (!is_object($definition)) { if (!is_object($definition)) {
$definition = !is_array($definition) ? ['class' => $definition] : $definition; $definition = !is_array($definition) ? ['class' => $definition] : $definition;
$definition = ArrayHelper::merge($this->definitions[$name], $definition); $definition = ArrayHelper::merge($this->defaultComponentDefinitions()[$name], $definition);
} }
$this->components[$name] = $definition; $this->components[$name] = $definition;
@@ -241,6 +231,20 @@ class Service extends Component implements ServiceInterface
return \Yii::createObject($definition, $params); return \Yii::createObject($definition, $params);
} }
/**
* @return array
*/
protected function defaultComponentDefinitions()
{
return [
'client' => ['class' => 'Aws\S3\S3Client'],
'resolver' => ['class' => 'frostealth\yii2\aws\s3\HandlerResolver'],
'bus' => ['class' => 'frostealth\yii2\aws\s3\Bus'],
'builder' => ['class' => 'frostealth\yii2\aws\s3\CommandBuilder'],
'factory' => ['class' => 'frostealth\yii2\aws\s3\CommandFactory'],
];
}
/** /**
* @param string $name * @param string $name
* *