2017 © Pedro Peláez
 

library tactician-symfony-events

Tactician middleware for the Symfony event dispatcher.

image

chrisguitarguy/tactician-symfony-events

Tactician middleware for the Symfony event dispatcher.

  • Thursday, February 11, 2016
  • by chrisguitarguy
  • Repository
  • 1 Watchers
  • 3 Stars
  • 4,435 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 23 % Grown

The README.md

Tactician Symfony Event Middleware

Use the Symfony event dispatcher to get notifications when a command is received, handled, and/or errors in Tactician., (*1)

Usage

Add the middleware anywhere anywhere before the command handler middleware., (*2)

use Symfony\Component\EventDispatcher\EventDispatcher;
use League\Tactician\CommandBus;
use Chrisguitarguy\Tactician\SymfonyEvents\EventMiddleware;
use Chrisguitarguy\Tactician\SymfonyEvents\CommandRecieved;
use Chrisguitarguy\Tactician\SymfonyEvents\CommandHandled;
use Chrisguitarguy\Tactician\SymfonyEvents\CommandFailed;

$eventMiddleware = new EventMiddlware($dispatcher = new EventDispatcher());

$commandBus = new CommandBus([
  // ...
  $eventMiddleware,
  $commandHandlerMiddleware,
  // ...
]);

You can listen for events specific to a single command., (*3)

use Acme\Example\SomeCommand;

$dispatcher->addListener('command.receieved.'.MyCommand::class, function (CommandReceived $event) {
    // called before the handler runs on SomeCommand
});

$dispatcher->addListener('command.handled.'.MyCommand::class, function (CommandHandled $event) {
    // called after the handler runs on SomeCommand
});

$dispatcher->addListener('command.failed.'.MyCommand::class, function (CommandFailed $event) {
    // called if one the handler or one of the `received` or `handled`
    // events throws an exeception from handling SomeCommand
});

$commandBus->execute(new SomeCommand());

Or listen to more generic events that fire on all commands., (*4)

use Acme\Example\SomeCommand;

$dispatcher->addListener('command.receieved', function (CommandReceived $event) {
    // called before the handler runs on all commands
});

$dispatcher->addListener('command.handled', function (CommandHandled $event) {
    // called after the handler runs on all commands
});

$dispatcher->addListener('command.failed', function (CommandFailed $event) {
    // called if one the handler or one of the `received` or `handled`
    // events throws an exception from handling any command
});

$commandBus->execute(new SomeCommand());

There's also a CommandEvents class that provides some constants and helpers for event names., (*5)

use Chrisguitarguy\Tactician\SymfonyEvents\CommandEvents;
use Acme\Example\SomeCommand;

// generic events are in constants.
$dispatcher->addListener(CommandEvents::RECEIVED, /*...*/);

// specific have helpers that take an object or class name
$dispatcher->addListener(CommandEvents::received(SomeCommand::class), /*...*/);

$command = new SomeCommand();
$dispatcher->addListener(CommandEvents::received($command), /*...*/);

$dispatcher->addListener(CommandEvents::HANDLED, /*...*/);
$dispatcher->addListener(CommandEvents::handled(SomeCommand::class), /*...*/);

$dispatcher->addListener(CommandEvents::FAILED, /*...*/);
$dispatcher->addListener(CommandEvents::failed(SomeCommand::class), /*...*/);

License

MIT. See the LICENSE file., (*6)

The Versions

11/02 2016

dev-master

9999999-dev

Tactician middleware for the Symfony event dispatcher.

  Sources   Download

MIT

The Requires

 

The Development Requires

events symfony tactician

11/02 2016

1.0.0

1.0.0.0

Tactician middleware for the Symfony event dispatcher.

  Sources   Download

MIT

The Requires

 

The Development Requires

events symfony tactician