Skip to content

Commit

Permalink
Merge pull request #9 from Jeckel-Lab/update-abstract-handler
Browse files Browse the repository at this point in the history
Update abstract handler
  • Loading branch information
jeckel committed Dec 5, 2019
2 parents 9d25f4f + 2118635 commit d671b08
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/CommandHandler/CommandHandlerAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
namespace JeckelLab\CommandDispatcher\CommandHandler;

use JeckelLab\CommandDispatcher\Command\CommandInterface;
use JeckelLab\CommandDispatcher\CommandResponse\CommandResponse;
use JeckelLab\CommandDispatcher\CommandResponse\CommandResponseInterface;
use JeckelLab\CommandDispatcher\Exception\InvalidCommandException;

/**
Expand All @@ -32,4 +34,25 @@ protected function validateCommand(CommandInterface $command): void
get_class($command)
));
}

/**
* @param CommandInterface $command
* @return CommandResponseInterface
*/
public function __invoke(CommandInterface $command): CommandResponseInterface
{
$this->validateCommand($command);

return $this->process($command, new CommandResponse());
}

/**
* @param CommandInterface $command
* @param CommandResponseInterface $commandResponse
* @return CommandResponseInterface
*/
abstract protected function process(
CommandInterface $command,
CommandResponseInterface $commandResponse
): CommandResponseInterface;
}

0 comments on commit d671b08

Please sign in to comment.