adamstipak / nette-cqrs-commands
为 Nette 框架提供的简单 CQRS 命令
1.0.0
2015-01-10 20:49 UTC
Requires
- nette/nette: 2.2.*
- simple-bus/command-bus: ~1.0
Requires (Dev)
- phpunit/phpunit: 4.4.*
This package is not auto-updated.
Last update: 2024-09-14 16:29:24 UTC
README
###将命令与 Nette 中的服务连接。
此扩展提供 CQRS 命令的简单实现。
安装
安装 Nette-CQRS-Commands 的最佳方式是使用 Composer
$ composer require adamstipak/nette-cqrs-commands
用法
命令 的示例
use SimpleBus\Command\Command; class FooCommand implements Command { public function __construct(...) { // your code } /** * @return string */ public function name() { return 'foo'; // identificator of command } }
命令处理器 的示例
use SimpleBus\Command\Command; use SimpleBus\Command\Handler\CommandHandler; class FooCommandHandler implements CommandHandler { /** * @param FooCommand $command */ public function handle(Command $command) { // $command is instance of FooCommand } }
在 config.neon
中注册所有内容。
services: fooCommandHandler: FooCommandHandler # your service extensions: events: AdamStipak\Commands\DI\CommandsExtension commands: # mapping commands to handlers handlers: foo: @fooCommandHandler # configuration (here is default values so you can avoid this lines) commandResolver: \AdamStipak\Commands\Command\DefaultCommandResolver handlerResolver: \AdamStipak\Commands\Handler\DefaultHandlerResolver bus: \AdamStipak\Commands\Bus\DefaultBus
展示者 的示例
class FooPresenter extends Nette\Application\UI\Presenter { /** * @var AdamStipak\Commands\Bus\DefaultBus * @inject */ public $commands; public function actionBar() { // ... your code here ... $this->commands->handle(new FooCommand(...)); // send the command to command bus (model) } }