rosamarsky/laravel-command-bus
最新稳定版本:2.0.1
Composer 安装命令:
composer require rosamarsky/laravel-command-bus
包简介
Simple Command Bus for Laravel framework
README 文档
README
Simple Command Bus for Laravel framework
Installation
composer require rosamarsky/laravel-command-bus
If your Laravel version is less than 5.5, add the following line to the providers array in config / app.php:
Rosamarsky\CommandBus\CommandBusServiceProvider::class,
Example
class UserController extends AbstractController { public function store(Request $request) { $user = $this->dispatch(new RegisterUser( $request->input('email'), $request->input('password') )); return $user; } }
Usage
Command
class RegisterUser implements \Rosamarsky\CommandBus\Command { private $email; private $password; public function __construct(string $email, string $password) { $this->email = $email; $this->password = $password; } public function email(): string { return $this->email; } public function password(): string { return $this->password; } }
Handler
class RegisterUserHandler implements \Rosamarsky\CommandBus\Handler { private $userRepository; public function __construct(UserRepository $userRepository) { $this->userRepository = $userRepository; } public function handle(\Rosamarsky\CommandBus\Command $command): User { $user = new User( $command->email(), $command->password() ); $this->userRepository->store($user); return $user; } }
Controllers
class AbsctractController extends \Illuminate\Routing\Controller { private $dispatcher; public function __construct(\Rosamarsky\CommandBus\CommandBus $dispatcher) { $this->dispatcher = $dispatcher; } public function dispatch(\Rosamarsky\CommandBus\Command $command) { return $this->dispatcher->execute($command); } }
class UserController extends AbstractController { public function store(Request $request) { $user = $this->dispatch(new RegisterUser( $request->input('email'), $request->input('password') )); return $user; } }
统计信息
- 总下载量: 15.84k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-03-20