Commander
Commander copied to clipboard
Decorator error when command is triggering another command
Hi,
I have the following logica in my app: A command is creating a player which is firing a event which checks if the player already has an alias, if not it will create it using another command. The first command has a decorator. When the second command is firing it is also hitting the decorator given in the first command which should not happen.
Regards, Ronnie
Yeah, I’m running into this too. For instance when registering a user, I want to issue 3 commands:
- Create the User
- Send them the Activation email
- Log them in
This fails to work:
$this->execute(
RegisterUserCommand::class,
null, # when null, it’s really Input::all()
# Decorators
[
'Acme\Decorators\AssignIdAsUUID',
'Acme\Decorators\SplitUserName',
'Acme\Decorators\RemoveFullName',
'Acme\Decorators\AssignUserLanguage',
'Acme\Decorators\LookupUserGravatar',
]
);
$this->execute(SendActivationEmailCommand::class, Input::only('email'));
$this->execute(BypassLoginCommand::class, Input::only('email'));
The decorators continue to survive the execution in the CommandBus. They really should be reset with each call to $this->execute()
. I tried passing an empty array and that did not work either.
I’m going to see if I can ferret out the issue directly, but I would love to hear from @JeffreyWay on this one.
humm the CommandBus should remove the decorator after excecute it. Another point to me is the result of decorators don't change the command object. I've expected the decorators to be transformers to. Am I missing something here?
I found a solution. There is a bit of code duplication between the ValidatorCommandBus
and the DefaultCommandBus
, but without stepping on @JeffreyWay’s toes there, I’ve got a solution. I will set up a Pull Request momentarily.