Skip to content

Commit

Permalink
some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
frostealth committed Apr 11, 2016
1 parent dad9f20 commit a335185
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 24 deletions.
2 changes: 2 additions & 0 deletions grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ parameters:
git_dir: .
bin_dir: ./vendor/bin
tasks:
phpcs:
standard: "PSR2"
git_blacklist:
keywords:
- "die("
Expand Down
4 changes: 2 additions & 2 deletions src/base/Bus.php → src/Bus.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace frostealth\yii2\aws\s3\base;
namespace frostealth\yii2\aws\s3;

use frostealth\yii2\aws\s3\interfaces;

/**
* Class Bus
*
* @package frostealth\yii2\aws\s3\base
* @package frostealth\yii2\aws\s3
*/
class Bus implements interfaces\Bus
{
Expand Down
4 changes: 2 additions & 2 deletions src/base/CommandBuilder.php → src/CommandBuilder.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace frostealth\yii2\aws\s3\base;
namespace frostealth\yii2\aws\s3;

use frostealth\yii2\aws\s3\interfaces;

/**
* Class CommandBuilder
*
* @package frostealth\yii2\aws\s3\base
* @package frostealth\yii2\aws\s3
*/
class CommandBuilder implements interfaces\CommandBuilder
{
Expand Down
6 changes: 3 additions & 3 deletions src/base/CommandFactory.php → src/CommandFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?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\ExistCommand;
Expand All @@ -15,12 +15,12 @@
/**
* Class CommandFactory
*
* @package frostealth\yii2\aws\s3\base
* @package frostealth\yii2\aws\s3
*/
class CommandFactory
{
/** @var \frostealth\yii2\aws\s3\interfaces\CommandBuilder */
private $builder;
protected $builder;

/**
* CommandFactory constructor.
Expand Down
17 changes: 14 additions & 3 deletions src/base/HandlerResolver.php → src/HandlerResolver.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace frostealth\yii2\aws\s3\base;
namespace frostealth\yii2\aws\s3;

use Aws\S3\S3Client;
use frostealth\yii2\aws\s3\handlers\PlainCommandHandler;
Expand All @@ -11,13 +11,16 @@
/**
* Class HandlerResolver
*
* @package frostealth\yii2\aws\s3\base
* @package frostealth\yii2\aws\s3
*/
class HandlerResolver extends Object implements interfaces\HandlerResolver
{
/** @var array */
protected $handlers = [];

/** @var string */
protected $plainCommandHandlerClassName = PlainCommandHandler::class;

/** @var \Aws\S3\S3Client */
protected $s3Client;

Expand Down Expand Up @@ -50,7 +53,7 @@ public function resolve(interfaces\commands\Command $command): interfaces\handle
}

if ($command instanceof interfaces\commands\PlainCommand) {
return $this->createHandler(PlainCommandHandler::class);
return $this->createHandler($this->plainCommandHandlerClassName);
}

$handlerClass = $commandClass . 'Handler';
Expand Down Expand Up @@ -85,6 +88,14 @@ public function setHandlers(array $handlers)
}
}

/**
* @param string $className
*/
public function setPlainCommandHandler(string $className)
{
$this->plainCommandHandlerClassName = $className;
}

/**
* @param string|array $type
*
Expand Down
32 changes: 18 additions & 14 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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'])) {
Expand All @@ -77,7 +67,7 @@ public function init()
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;
}
}
Expand Down Expand Up @@ -109,7 +99,7 @@ public function create(string $commandClass): Command
/**
* Returns command factory.
*
* @return \frostealth\yii2\aws\s3\base\CommandFactory
* @return \frostealth\yii2\aws\s3\CommandFactory
*/
public function commands(): CommandFactory
{
Expand Down Expand Up @@ -221,7 +211,7 @@ protected function setComponent(string $name, $definition)
{
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;
Expand All @@ -241,6 +231,20 @@ protected function createComponent(string $name)
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
*
Expand Down

0 comments on commit a335185

Please sign in to comment.