Componette

Componette

newPOPE

newPOPE / Nette-CQRS-Commands

Simple CQRS Commands for Nette Framework

download-cloud-line composer require adamstipak/nette-cqrs-commands

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

}

No release at this moment. Try to create first one.

bar-chart-fill

Statistics

download-cloud-fill
22
star-fill
3
bug-fill
0
flashlight-fill
9.3y
price-tag-2-line

Badges

guide-fill

Dependencies

Componette Componette felix@nette.org