gbprod/domain-event

This package is abandoned and no longer maintained. No replacement package was suggested.

Library to manage domain events in a php DDD application

v0.1.0 2016-03-11 18:18 UTC

This package is auto-updated.

Last update: 2020-06-07 07:57:05 UTC


README

stability-deprecated

Build Status Scrutinizer Code Quality Code Coverage

Latest Stable Version Total Downloads Latest Unstable Version License

Library to manage domain events in a php DDD application.

Usage

Create a domain event

<?php

namespace GBProd\Acme\Event;

use GBProd\DomainEvent\DomainEvent;

class SomethingHappenedEvent implements DomainEvent
{
    private $id;
    
    public function __construct($id)
    {
        $this->id = $id;
    }
    
    public function getAggregateId()
    {
        return $id;
    }
}

Raise your event

<?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

<?php

namespace GBProd\Acme\Repository;

use GBProd\DomainEvent\EventProvider;

class MyEntityRepository
{
    public function save(MyEntity $entity)
    {
        $this->persist($entity);
        
        $this->dispatcher->dispatch($entity);
    }
}

Requirements

  • PHP 5.5+

Installation

Using composer

composer require gbprod/domain-event