Skip to content
Simple CQRS Commands for Nette Framework
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/AdamStipak/Commands
tests
.gitignore
.travis.yml
LICENSE
README.md
composer.json
composer.lock

README.md

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

}
You can’t perform that action at this time.