Commander icon indicating copy to clipboard operation
Commander copied to clipboard

Decorator error when command is triggering another command

Open ronnievisser opened this issue 10 years ago • 3 comments

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

ronnievisser avatar Aug 04 '14 14:08 ronnievisser

Yeah, I’m running into this too. For instance when registering a user, I want to issue 3 commands:

  1. Create the User
  2. Send them the Activation email
  3. 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.

aarongustafson avatar Aug 13 '14 18:08 aarongustafson

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?

bruno-barros avatar Aug 13 '14 18:08 bruno-barros

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.

aarongustafson avatar Aug 13 '14 18:08 aarongustafson