Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axing persistent decorators #27

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Laracasts/Commander/CommanderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -81,4 +88,4 @@ protected function mapInputToCommand($command, array $input)
return $class->newInstanceArgs($dependencies);
}

}
}
13 changes: 12 additions & 1 deletion src/Laracasts/Commander/DefaultCommandBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -81,4 +92,4 @@ protected function executeDecorators($command)
}
}

}
}
11 changes: 11 additions & 0 deletions src/Laracasts/Commander/ValidationCommandBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down