2017 © Pedro Peláez
 

symfony-bundle domain-event-dispatcher-bundle

Symfony bundle to add the domain event dispatcher (singleton)

image

ashleydawson/domain-event-dispatcher-bundle

Symfony bundle to add the domain event dispatcher (singleton)

  • Sunday, January 1, 2017
  • by AshleyDawson
  • Repository
  • 1 Watchers
  • 2 Stars
  • 9,990 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 8 % Grown

The README.md

Domain Event Dispatcher Bundle

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

Installation

Install the bundle via Composer:, (*2)

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

Then, register the bundle with the Symfony kernel app/AppKernel.php:, (*3)

$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:, (*4)

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:, (*5)

Create an event:, (*6)

<?php

namespace AppBundle\DomainEvent;

class MyDomainEvent
{
    private $myEntityId;

    public function __construct($myEntityId)
    {
        $this->myEntityId = $myEntityId;
    }

    public function getMyEntityId()
    {
        return $this->myEntityId;
    }
}

Create a listener:, (*7)

<?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:, (*8)

# 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:, (*9)

<?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., (*10)

Toolbar Info:, (*11)

Toolbar, (*12)

Full Profiler Screen:, (*13)

Profiler Screen, (*14)

The Versions

01/01 2017

dev-master

9999999-dev

Symfony bundle to add the domain event dispatcher (singleton)

  Sources   Download

MIT

The Requires

 

by Ashley Dawson

domain bundle dispatcher symfony subscriber event listener ddd

01/01 2017

v1.0.2

1.0.2.0

Symfony bundle to add the domain event dispatcher (singleton)

  Sources   Download

MIT

The Requires

 

by Ashley Dawson

domain bundle dispatcher symfony subscriber event listener ddd

01/01 2017

1.0.1

1.0.1.0

Symfony bundle to add the domain event dispatcher (singleton)

  Sources   Download

MIT

The Requires

 

by Ashley Dawson

domain bundle dispatcher symfony subscriber event listener ddd

30/12 2016

1.0.0

1.0.0.0

Symfony bundle to add the domain event dispatcher (singleton)

  Sources   Download

MIT

The Requires

 

by Ashley Dawson

domain bundle dispatcher symfony subscriber event listener ddd