PHP code example of ashleydawson / domain-event-dispatcher-bundle

1. Go to this page and download the library: Download ashleydawson/domain-event-dispatcher-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ashleydawson / domain-event-dispatcher-bundle example snippets


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



namespace AppBundle\DomainEvent;

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



namespace AppBundle\DomainEventListener;

use AppBundle\DomainEvent\MyDomainEvent;

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



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)
        );
    }
}