定制 bornfree/tactician-doctrine-domain-events 二次开发

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

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

bornfree/tactician-doctrine-domain-events

Composer 安装命令:

composer require bornfree/tactician-doctrine-domain-events

包简介

The bridge to provide Domain Events handling with Tactician command bus and Doctrine ORM

README 文档

README

Build Status codecov Scrutinizer Code Quality Latest Stable Version

The bridge to provide Domain Events handling with Tactician command bus and Doctrine ORM

Installation

Install via composer

composer require bornfree/tactician-doctrine-domain-events

Usage

Using the events recorder facilities you can let Doctrine ORM collect domain events and subsequently let the EventDispatcher handle them.

Make sure that your entities implement the ContainsRecordedMessages interface. Use the EventRecorderCapabilities trait from Tactician Domain Events library to conveniently record events from inside the entity:

use BornFree\TacticianDomainEvent\Recorder\ContainsRecordedEvents;
use BornFree\TacticianDomainEvent\Recorder\EventRecorderCapabilities;

class Task implements ContainsRecordedMessages
{
    use EventRecorderCapabilities;

    public function __construct($name)
    {
        $this->record(new TaskWasCreated($name));
    }
}

Then set up the event recorder for Doctrine entities:

use BornFree\TacticianDoctrineDomainEvent\EventListener\CollectsEventsFromEntities;

$eventRecorder = new CollectsEventsFromEntities();

$entityManager->getConnection()->getEventManager()->addEventSubscriber($eventRecorder);
Syfmony integration

This listener will be registered automatically with Symfony, see the documentation

The event recorder will loop over all the entities that were involved in the last database transaction and collect their internally recorded events.

After a database transaction was completed successfully these events should be handled by the EventDispatcher. This is done by a specialized middleware, which should be added to the command bus before the middleware that is responsible for handling the transaction.

use League\Tactician\CommandBus;
use League\Tactician\Doctrine\ORM\TransactionMiddleware;
use namespace BornFree\TacticianDomainEvent\Middleware\ReleaseRecordedEventsMiddleware;

// see the previous sections about $eventRecorder and $eventDispatcher
$releaseRecordedEventsMiddleware = new ReleaseRecordedEventsMiddleware($eventRecorder, $eventDispatcher);

$commandBus = new CommandBus(
    [
        $releaseRecordedEventsMiddleware, // it should be before transaction middleware
        $transactionMiddleware,
        $commandHandlerMiddleware
    ]
);

License

Copyright (c) 2017, Maks Rafalko

Under MIT license, read LICENSE file.

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-01-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固