I have a few complex commands that I split up into "sub commands" (Example following). As my site is multi-domain, I need the capability of customizing the sequence and composition of the sub commands to perform (so far I had this in a config under L4). With the migration to L5, I'm refactoring this functionality using the Command bus.
Example of a command sequence: Site A:
1) AuthorizeCharge
2) DoSomethingA
3) DoSomethingB
4) Charge
Site B
1) AuthorizeCharge
2) DoSomethingA
3) DoSomethingC
4) DoSomethingD
5) Charge
Each of these line items is a Command with it's Handler. This part is fairly clear to me (and works fine).
How can I dispatch this elegantly in my controller?
Here is what I already tried.
Fixed version (works)(in controller):
$return = $this->dispatch( new DoSomethingACommand($form));
$return[] = $this->dispatch( new DoSomethingBCommand($form));
Variable version (pseudo code):
someconfig.php
return [
'DoSomethingACommand',
'DoSomethingBCommand'
];
App\Namespace\Http\Controller\SomeController.php
...
//loop over all scenario commands
for ($j = 0; $j < count($commands); $j++)
{
//make the object which we need to act on
$object = \App::make( $this->_namespace . '\\'. $commands[ $j ] );
$return[] = $this->dispatchFrom( $object, $form ); //Doesnt work
}
I'm a bit stuck on how to solve this. Any advice on how I could implement this?