2017 © Pedro Peláez
 

bundle domain-event-bundle

Integrates domain event library to a Symfony application

image

gbprod/domain-event-bundle

Integrates domain event library to a Symfony application

  • Monday, September 12, 2016
  • by gbprod
  • Repository
  • 1 Watchers
  • 2 Stars
  • 121 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Domain event bundle

stability-deprecated, (*1)

Build Status Scrutinizer Code Quality Code Coverage, (*2)

Latest Stable Version Total Downloads Latest Unstable Version License, (*3)

Integrates domain event library to a Symfony application, (*4)

Installation

With composer :, (*5)

composer require gbprod/domain-event-bundle

Update your app/AppKernel.php file:, (*6)

public function registerBundles()
{
    $bundles = array(
        new GBProd\DomainEventBundle\DomainEventBundle(),
    );
}

Setup your entity

Use domain event library to raise events :, (*7)

<?php

namespace GBProd\Acme\Entity;

use GBProd\DomainEvent\EventProvider;
use GBProd\DomainEvent\EventProviderTrait;

final class MyEntity implements EventProvider
{
    use EventProviderTrait;

    public function doSomething()
    {
        $this->raise(
            new SomethingHappenedEvent($this->id)
        );
    }
}

Dispatch events from your repository

Example with Doctrine repository :, (*8)

<?php

namespace GBProd\AcmeBundle\Repository;

use GBProd\DomainEvent\EventProvider;
use GBProd\DomainEvent\Dispatcher;

class MyEntityRepository
{
    public function __construct(EntityManager $em, DomainEventDispatcher $dispatcher)
    {
        $this->em         = $em;
        $this->dispatcher = $dispatcher;
    }

    public function save(MyEntity $entity)
    {
        $this->em->persist($entity);
        $this->em->flush();

        $this->dispatcher->dispatch($entity);
    }
}
# src/GBProd/AcmeBundle/Resourses/config/services.yml
services:
    gbprod_acme.my_entity_repository:
        class: GBProd\AcmeBundle\Repository\MyEntityRepository
        arguments:
            - "@doctrine.entity_manager"
            - "@gbprod.domain_event_dispatcher"

This will dispatch events using Symfony Event dispatcher. The name of the event will be the classname of the aggregate and the event (MyEntity.SomethingHappenedEvent in this example)., (*9)

Create your listener

<?php

namespace GBProd\AcmeBundle\Listener;

use Symfony\Component\EventDispatcher\Event;

class MyListener
{
    public function onSomethingHappened(Event $event) 
    {
        $domainEvent = $event->getDomainEvent();

        // Use it now
    }
}

Register your listener

gbprod_acme.event_listener.my_listener:
    class: GBProd\AcmeBundle\Listener\MyListener
    tags:
        - { name: kernel.event_listener, event: MyEntity.SomethingHappenedEvent, method: 'onSomethingHappened' }

The Versions

12/09 2016

dev-master

9999999-dev

Integrates domain event library to a Symfony application

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar gbprod

12/03 2016

v0.1.1

0.1.1.0

Integrates domain event library to a Symfony application

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar gbprod

11/03 2016

v0.1.0

0.1.0.0

Integrates domain event library to a Symfony application

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar gbprod

11/03 2016

v0.1-alpha.3

0.1.0.0-alpha3

Integrates domain event library to a Symfony application

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar gbprod

11/03 2016

v0.1-alpha.1

0.1.0.0-alpha1

Integrates domain event library to a Symfony application

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar gbprod

11/03 2016

v0.1-alpha.0

0.1.0.0-alpha0

Integrates domain event library to a Symfony application

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar gbprod