We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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 (http://simplebus.github.io/MessageBus/) and Tactician (http://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 : http://culttt.com/2014/11/10/creating-using-command-bus/