承接 ashleydawson/domain-event-dispatcher-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ashleydawson/domain-event-dispatcher-bundle

Composer 安装命令:

composer require ashleydawson/domain-event-dispatcher-bundle

包简介

Symfony bundle to add the domain event dispatcher (singleton)

README 文档

README

Brings the domain event dispatcher (singleton) to Symfony projects. For full usage instructions, please see the full documentation shipped with the library.

Installation

Install the bundle via Composer:

$ composer require ashleydawson/domain-event-dispatcher-bundle

Then, register the bundle with the Symfony kernel app/AppKernel.php:

$bundles = [
    // ...
    new AshleyDawson\DomainEventDispatcherBundle\AshleyDawsonDomainEventDispatcherBundle(),
];

Configuration

Deferred events are configured to be dispatched from the Symfony kernel.terminate kernel event. To change this, add the following to your app/config/config.yml file:

ashley_dawson_domain_event_dispatcher:
    dispatch_deferred_events_from_kernel_event: kernel.terminate
    dispatch_deferred_events_from_kernel_event_priority: 0

Usage

Please refer to the full documentation for an in-depth look at how to use the domain event dispatcher. However, please find a simple example below:

Create an event:

<?php

namespace AppBundle\DomainEvent;

class MyDomainEvent
{
    private $myEntityId;
    
    public function __construct($myEntityId)
    {
        $this->myEntityId = $myEntityId;
    }
    
    public function getMyEntityId()
    {
        return $this->myEntityId;
    }
}

Create a listener:

<?php

namespace AppBundle\DomainEventListener;

use AppBundle\DomainEvent\MyDomainEvent;

class MyDomainEventListener
{
    public function __invoke(MyDomainEvent $event)
    {
        // Do something with the event...
    }
}

Add the listener to the event dispatcher via the Symfony Dependency Injection Container using the tag ashley_dawson.domain_event_listener:

# app/config/services.yml

services:
    app.my_domain_event_listener:
        class: AppBundle\DomainEventListener\MyDomainEventListener
        tags:
            - { name: ashley_dawson.domain_event_listener }

Dispatch an event from your model:

<?php

namespace AppBundle\Entity;

use AshleyDawson\DomainEventDispatcher\DomainEventDispatcher;
use AppBundle\DomainEvent\MyDomainEvent;

class MyEntity
{
    private $id;
    
    public function mySpecialCommand()
    {
        DomainEventDispatcher::getInstance()->dispatch(
            new MyDomainEvent($this->id)
        );
    }
}

Symfony Profiler

The map of events that have been deferred/dispatched during a request can be found in the Symfony Profiler. Simply click on the domain events icon and the profile screen containing the map will be displayed.

Toolbar Info:

Toolbar

Full Profiler Screen:

Profiler Screen

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-12-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固