Skip to content

Commit

Permalink
Merge pull request #2 from php-api-clients/improvement-replace-getter…
Browse files Browse the repository at this point in the history
…s-n-setters-with-a-commandbus

Replace getters/setters with command bus
  • Loading branch information
WyriHaximus committed Sep 17, 2016
2 parents 9680643 + 86a6213 commit bb7a334
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 47 deletions.
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -11,7 +11,8 @@
],
"require": {
"php": "^7.0",
"api-clients/hydrator": "dev-master"
"api-clients/hydrator": "dev-master",
"league/tactician": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.2.3",
Expand Down
116 changes: 83 additions & 33 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 12 additions & 13 deletions src/AbstractResource.php
Expand Up @@ -2,26 +2,25 @@

namespace ApiClients\Foundation\Resource;

use ApiClients\Foundation\Hydrator\HydrateTrait;
use League\Tactician\CommandBus;

abstract class AbstractResource implements ResourceInterface
{
use HydrateTrait;
/**
* @var CommandBus
*/
private $commandBus;

public function setExtraProperties(array $properties)
final public function __construct(CommandBus $commandBus)
{
foreach ($properties as $key => $value) {
$this->setPropertyValue($key, $value);
}
$this->commandBus = $commandBus;
}

private function setPropertyValue(string $key, $value)
/**
* @return CommandBus
*/
protected function getCommandBus()
{
$methodName = $key . 'Setter';
if (!method_exists($this, $methodName)) {
return;
}

$this->$methodName($value);
return $this->commandBus;
}
}
3 changes: 3 additions & 0 deletions src/ResourceInterface.php
Expand Up @@ -2,6 +2,9 @@

namespace ApiClients\Foundation\Resource;

use League\Tactician\CommandBus;

interface ResourceInterface
{
public function __construct(CommandBus $commandBus);
}

0 comments on commit bb7a334

Please sign in to comment.