No description, website, or topics provided.
Failed to load latest commit information.
spec/Knp/Rad/DomainEvent/Dispatcher Updated Mar 4, 2016
src/Knp/Rad/DomainEvent Initial commit Jun 24, 2015
.gitignore Initial commit Jun 24, 2015
.travis.yml Add PHP7 tests Mar 5, 2016
LICENSE Initial commit Jun 24, 2015

Knp Rad Domain Event

Build Status Scrutinizer Code Quality Latest Stable Version Total Downloads Latest Unstable Version License

A lightweight domain event pattern implementation for Doctrine2.


With composer :

$ composer require knplabs/rad-domain-event

If you are using Symfony you can update your app/AppKernel.php file:

public function registerBundles()
    $bundles = array(
        // bundles here ...
        new Knp\Rad\DomainEvent\Bundle\DomainEventBundle();


Setup your entity

First, make sure your entity implements the Provider interface and uses the ProviderTrait.

use Knp\Rad\DomainEvent;

class MyEntity implements DomainEvent\Provider
    use DomainEvent\ProviderTrait;

Raise event

Trigger any event from your entity, through the raise method. It will be turned into a Knp\Rad\DomainEvent\Event object and dispatched once your entity has been flushed.

use Knp\Rad\DomainEvent;

class MyEntity implements DomainEvent\Provider
    // ...
    public function myFunction($arg) {
        // your function behavior
        $this->raise('myEventName', ['anyKey' => $anyValue]);

Listen to this event

use Knp\Rad\DomainEvent\Event;

class MyListener
    public function onMyEventName(Event $event) {
        // your function behavior     

Then, of course, register your listener.

    class: App\EventListener\MyEventListener
        - { name: kernel.event_listener, event: myEventName, method: 'onMyEventName' }