Download the PHP package robrogers3/commandbus without Composer
On this page you can find all versions of the php package robrogers3/commandbus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download robrogers3/commandbus
More information about robrogers3/commandbus
Files in robrogers3/commandbus
Package commandbus
Short Description commandbus for php53
License MIT
Homepage https://github.com/robrogers3/commandbus
Informations about the package commandbus
CommandBus
This a CommandBus implementation for php5.3. It's based on illuminate/events. This though will require a few other packages: illuminate/support, illuminate/contracts, and illuminate/container.
A CommandBus allows you to leverage commands and domain events in your php projects.
Essentially, the value add is to replace lines and lines of procedural style code in a class or method, with classes that do one thing. These classes are loosely coupled together through eventing initiated by the CommandBus and CommandHandlers.
The usage shown below is the best explanation.
Install
Via Composer
Usage
Requirements:
You have an app which uses illimunate packages. Especially illimunate/events.
Your Goal:
Have a way to accomplish some task which takes many subtasks. Perhaps currently you have the subtasks inside one class or even just one method. Some kind of God Object.
The Solution:
Use a command bus to kick off (dispatch) the necessary classes to complete accomplish what was done in one place.
Initial Setup:
You need to create a boot method or function that initialize the illuminate Container (IOC). This method should:
- Register the container.
- Create an INSTANCE of the illimunate/event dispatcher.
- Register all the listeners for your events. * The listeners can be fully written out, like 'Acme\UserHasRegistered'. Or better, 'Acme.' The latter can catch all events prefixed by Acme
-
Define your listeners
- In your boot method, register them:
Get to Work
1) Create your command. It's a simple class, a DTO of sorts. This is what gets thrown into the commandbus. Here is a simple one
2) Next, lets create a listener, like:
3) Create your command handler. The commandbus calls the handle method on this class.
4) Finally create the 'event' we are listening for. This also a DTO, which contains the above UserRegister $command.
5) Use it:
6) See what happens:
If you have registered the three listeners above, they all get fired.
- send a welcome email to the user.
- add them to ldap (or wherever)
- configure their system permissions
Bottom line in your controller, or wherever. You just need 3 lines:
- instantiate the command.
- make the command bus.
- call the execute method.
For the three tasks above, it's not a big deal to call them directly. But if you have many many things to do, then it cleans things up rather nicely.
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
Contributing
Please see CONDUCT for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Rob Rogers
- All Contributors
License
The MIT License (MIT). Please see License File for more information.