From a335185184effe20e370041fb8be76eaad81fab9 Mon Sep 17 00:00:00 2001 From: frostealth Date: Mon, 11 Apr 2016 23:21:50 +0600 Subject: [PATCH] some improvements --- grumphp.yml | 2 ++ src/{base => }/Bus.php | 4 ++-- src/{base => }/CommandBuilder.php | 4 ++-- src/{base => }/CommandFactory.php | 6 +++--- src/{base => }/HandlerResolver.php | 17 +++++++++++++--- src/Service.php | 32 +++++++++++++++++------------- 6 files changed, 41 insertions(+), 24 deletions(-) rename src/{base => }/Bus.php (90%) rename src/{base => }/CommandBuilder.php (95%) rename src/{base => }/CommandFactory.php (97%) rename src/{base => }/HandlerResolver.php (85%) diff --git a/grumphp.yml b/grumphp.yml index baf1ca1..afbf91a 100644 --- a/grumphp.yml +++ b/grumphp.yml @@ -2,6 +2,8 @@ parameters: git_dir: . bin_dir: ./vendor/bin tasks: + phpcs: + standard: "PSR2" git_blacklist: keywords: - "die(" diff --git a/src/base/Bus.php b/src/Bus.php similarity index 90% rename from src/base/Bus.php rename to src/Bus.php index 91d7626..56a1025 100644 --- a/src/base/Bus.php +++ b/src/Bus.php @@ -1,13 +1,13 @@ createHandler(PlainCommandHandler::class); + return $this->createHandler($this->plainCommandHandlerClassName); } $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 * diff --git a/src/Service.php b/src/Service.php index 4493a6c..2153ab6 100644 --- a/src/Service.php +++ b/src/Service.php @@ -3,7 +3,6 @@ namespace frostealth\yii2\aws\s3; use Aws\ResultInterface; -use frostealth\yii2\aws\s3\base\CommandFactory; use frostealth\yii2\aws\s3\interfaces\commands\Command; use frostealth\yii2\aws\s3\interfaces\HandlerResolver; use frostealth\yii2\aws\s3\interfaces\Service as ServiceInterface; @@ -49,15 +48,6 @@ class Service extends Component implements ServiceInterface /** @var array */ 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. * 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() { if (empty($this->clientConfig['credentials'])) { - throw new InvalidConfigException('Credentials is not set.'); + throw new InvalidConfigException('Credentials are not set.'); } if (empty($this->clientConfig['region'])) { @@ -77,7 +67,7 @@ class Service extends Component implements ServiceInterface 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; } } @@ -109,7 +99,7 @@ class Service extends Component implements ServiceInterface /** * Returns command factory. * - * @return \frostealth\yii2\aws\s3\base\CommandFactory + * @return \frostealth\yii2\aws\s3\CommandFactory */ public function commands(): CommandFactory { @@ -221,7 +211,7 @@ class Service extends Component implements ServiceInterface { if (!is_object($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; @@ -241,6 +231,20 @@ class Service extends Component implements ServiceInterface 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 *