desmart / laravel-commandbus
DeSmart CommandBus for Laravel
Installs: 3 395
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 0
Open Issues: 0
Requires
- php: >=5.6.0
- illuminate/container: 5.1.* | ~5.2
- illuminate/support: 5.1.* | ~5.2
Requires (Dev)
- phpspec/phpspec: ^2.4
This package is not auto-updated.
Last update: 2024-12-19 00:37:52 UTC
README
A small, pluggable command bus.
Instalation
$ composer require desmart/laravel-commandbus
- Add
DeSmart\CommandBus\ServiceProvider
toapp.php
Example usage:
Command Class
class RegisterUserCommand { protected $email; public function __construct($email) { $this->email = $email; } public function getEmail() { return $this->email; } }
CommandValidator Class
class RegisterUserCommandValidator { public function validate(RegisterUserCommand $command) { // it will be called before handler } }
CommandHandler Class
class RegisterUserCommandHandler { public function handle(RegisterUserCommand $command) { // it will be called if validator won't throw any exception } }
Execute the command:
class Controller { /** * @var \DeSmart\CommandBus\Contracts\CommandBus */ protected $commandBus; public function __construct(\DeSmart\CommandBus\Contracts\CommandBus $commandBus) { $this->commandBus = $commandBus; } public function index() { $command = new RegisterUserCommand("foo@bar.net"); $this->commandBus->handle($command); } }