Commander icon indicating copy to clipboard operation
Commander copied to clipboard

Decorators of the parent command will be executed on the child command

Open arminsam opened this issue 10 years ago • 1 comments

I have CommandA with ONE decorator class.

I have CommandB with NO decorator classes.

In CommandA handler, I execute CommandB.

By right, when I execute CommandA, these steps should happen:

1- Decorator of CommandA should be executed 2- CommandA handler should be called 3- CommandB handler should be called

However, I found that the decorator class of CommandA will execute twice:

1- Decorator of CommandA is executed 2- CommandA handler is called 3- Decorator of CommandA is executed again 4- CommandB handler is called

I managed to fix the issue by adding this check to CommanderTrait->execute() function:

if (empty($decorators))
{
    $bus->emptyDecorators();
}

where emptyDecorators() is defined in CommandBus implementation as:

/**
* Remove all 
*/
public function emptyDecorators ()
{
    $this->decorators = [];
}

Thanks.

arminsam avatar Jan 30 '15 13:01 arminsam

This was fixed already, BUT, it was not fixed in the version for Laravel 4. This definitely needs to be handled.

If you want to manually do it for now, in the ServiceProvider, changed bindShared to bind.

nesl247 avatar Jan 30 '15 14:01 nesl247