Last active
December 29, 2015 05:37
-
-
Save laracasts/6527c6009072c837a77c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ... | |
/** | |
* Register a decorator for the command bus. | |
* | |
* @param string $decorator | |
* @return CommandBus | |
*/ | |
public function decorate($decorator) | |
{ | |
$this->decorators[] = $decorator; | |
return $this; | |
} | |
/** | |
* Execute the command | |
* | |
* @param $command | |
* @return mixed | |
*/ | |
public function execute($command) | |
{ | |
$this->executeBusDecorators($command); | |
$handler = $this->commandNameTranslator->toHandler($command); | |
return $this->app->make($handler)->handle($command); | |
} | |
/** | |
* Execute any provided decorators. | |
* | |
* @param object $command | |
* @return null | |
*/ | |
protected function executeBusDecorators($command) | |
{ | |
foreach ($this->decorators as $decorator) | |
{ | |
$this->app->make($decorator)->execute($command); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This will: | |
- Channel the command through an input sanitizer | |
- Then on to a validator | |
- Then on to the normal processing, where it will trigger a handler to actually process the command. | |
$this->bus | |
->decorate('Foo\Bar\RegistrationFormSanitizer') | |
->decorate('Foo\Bar\RegistrationFormValidator') | |
->execute($registerUserCommand); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment