adamstipak / nette-cqrs-commands
Simple CQRS Commands for Nette Framework
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-10-26 16:59:23 UTC
README
###Connect Commands with services in Nette.
This extension provide a simle implementation of CQRS commands.
Installation:
The best way to install Nette-CQRS-Commands is using Composer:
$ composer require adamstipak/nette-cqrs-commands
Usage:
Example of Command:
use SimpleBus\Command\Command; class FooCommand implements Command { public function __construct(...) { // your code } /** * @return string */ public function name() { return 'foo'; // identificator of command } }
Example of CommandHandler:
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 } }
Register all things in 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
Example of Presenter:
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) } }