diff --git a/src/Laracasts/Commander/CommanderTrait.php b/src/Laracasts/Commander/CommanderTrait.php index 8a328f7..ee167de 100644 --- a/src/Laracasts/Commander/CommanderTrait.php +++ b/src/Laracasts/Commander/CommanderTrait.php @@ -26,9 +26,16 @@ public function execute($command, array $input = null, $decorators = []) // filter through and register them // with the CommandBus, so that they // are executed first. - foreach ($decorators as $decorator) + if ($decorators) { - $bus->decorate($decorator); + foreach ($decorators as $decorator) + { + $bus->decorate($decorator); + } + } + else + { + $bus->clearDecorators(); } return $bus->execute($command); @@ -81,4 +88,4 @@ protected function mapInputToCommand($command, array $input) return $class->newInstanceArgs($dependencies); } -} \ No newline at end of file +} diff --git a/src/Laracasts/Commander/DefaultCommandBus.php b/src/Laracasts/Commander/DefaultCommandBus.php index 79f8e1c..ba60d8c 100644 --- a/src/Laracasts/Commander/DefaultCommandBus.php +++ b/src/Laracasts/Commander/DefaultCommandBus.php @@ -43,6 +43,17 @@ public function decorate($className) $this->decorators[] = $className; } + /** + * Remove decorations from the command bus + * + * @param $className + * @return null + */ + public function clearDecorators() + { + $this->decorators = []; + } + /** * Execute the command * @@ -81,4 +92,4 @@ protected function executeDecorators($command) } } -} \ No newline at end of file +} diff --git a/src/Laracasts/Commander/ValidationCommandBus.php b/src/Laracasts/Commander/ValidationCommandBus.php index d33ddd9..8dcfb45 100644 --- a/src/Laracasts/Commander/ValidationCommandBus.php +++ b/src/Laracasts/Commander/ValidationCommandBus.php @@ -45,6 +45,17 @@ public function decorate($className) $this->decorators[] = $className; } + /** + * Remove decorations from the command bus + * + * @param $className + * @return null + */ + public function clearDecorators() + { + $this->decorators = []; + } + /** * Execute a command with validation. *