Home

Awesome

Simple CQRS Commands for Nette Framework

###Connect Commands with services in Nette.

This extension provide a simle implementation of CQRS commands.

Build Status

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)
  }

}