We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Command pattern (or command bus) - integrating simplebus or tactician

Hi,

I'm new to Phalcon (using 2.x beta), just getting everything configured in the DI container. Enjoying the posts here.

I don't see any type of "command bus pattern" in Phalcon. I've been doing this type of pattern for a while (9+ years) now getting shared "business logic" code out of the controllers but it looked more like (non-PSR)

$action = Action::factory('Do_Something')
                          ->bind('param1', $param1)
                          ->bind('param2', $param2)
                          ->send('param3', $param3)
                          ->perform();

 class Do_Something_Action extends Base_Action {
     var $_params = [];
     public function initialize() {}
     public function perform() {
         extract(...); // extra things in $this->_params into local scope
         echo $param3;
     }
 }

This is done to share business logic between Controllers (for example if the sequence of steps needs to be executed by a user interface controller, Ajax and API hits)

The bind(...) obviously doesn't really help auto-complete plus it is werd talking to people about it. It seems like the Command Bus patern is what it's called now

It seems like SimpleBus (https://simplebus.github.io/MessageBus/) and Tactician (https://tactician.thephpleague.com/) are the packages that are used. Doesn anybody have an example on how to get this into the DI of Phalcon? Specifically tying to the EventsManager & the rest of the framework?

Thanks, Chris



7.9k
Accepted
answer

I think is possible to implement it in phalcon, I have never use thos lib. I have created one from this tutorial : https://culttt.com/2014/11/10/creating-using-command-bus/