desmart / laravel-commandbus
DeSmart CommandBus for Laravel
1.1.1
2020-11-02 15:39 UTC
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-09-11 23:18:48 UTC
README
一个轻量级、可插拔的命令总线。
安装
$ composer require desmart/laravel-commandbus
- 将
DeSmart\CommandBus\ServiceProvider
添加到app.php
示例使用
命令类
class RegisterUserCommand { protected $email; public function __construct($email) { $this->email = $email; } public function getEmail() { return $this->email; } }
命令验证类
class RegisterUserCommandValidator { public function validate(RegisterUserCommand $command) { // it will be called before handler } }
命令处理器类
class RegisterUserCommandHandler { public function handle(RegisterUserCommand $command) { // it will be called if validator won't throw any exception } }
执行命令
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); } }