Skip to content

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

Open
@arminsam

Description

@arminsam

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions