Triggering executeDecorators before validateCommand (in ValidationCommandBus)
Opened this issue · 1 comments
When I use a decorator to sanitize data passed to the command, I would like to have that be executed before the validationCommand. The method below is from the ValidationCommandBus, but I've switched the $this->executeDecorators($command);
with $this->validateCommand($command);
.
Does swapping the order make sense for somebody else too? I can imagine there will be situations where this is not working as wanted (because you do want it to be validated first), but I would love to hear others opinions.
/**
* Execute a command with validation.
*
* @param $command
* @return mixed
*/
public function execute($command)
{
// Next, we'll execute any registered decorators.
$this->executeDecorators($command);
// If a validator is "registered," we will
// first trigger it, before moving forward.
$this->validateCommand($command);
// And finally pass through to the handler class.
return $this->bus->execute($command);
}
One workaround would be to ignore the Validator decorator naming convention and making a JobValidator and add it after the JobSanitizer.
$this->execute(PostJobListingCommand::class, null, [
'Acme\Job\JobSanitizer',
'Acme\Job\JobValidator'
]);
May be closed, I think it's better to trigger the validator before the custom decorators.