定制 chrisguitarguy/tactician-symfony-events 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

chrisguitarguy/tactician-symfony-events

最新稳定版本:v2.0.0-RC1

Composer 安装命令:

composer require chrisguitarguy/tactician-symfony-events

包简介

Tactician middleware for the Symfony event dispatcher.

README 文档

README

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

Usage

Add the middleware anywhere anywhere before the command handler middleware.

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.

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.

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.

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.

统计信息

  • 总下载量: 34.45k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-11