PHP code example of itmedia / domain-events

1. Go to this page and download the library: Download itmedia/domain-events 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/ */

    

itmedia / domain-events example snippets




use Itmedia\DomainEvents\Event\DomainEvent;

class AccountRegistrationEvent implements DomainEvent
{
    /**
     * @var Account
     */
    private $account;


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


    public function getName():string
    {
        return 'account_register';
    }

    // ...

}




use Itmedia\DomainEvents\Publisher\DomainEventPublisher;
use Itmedia\DomainEvents\Publisher\DomainEventPublisherTrait;

class Account implements DomainEventPublisher
{
    use DomainEventPublisherTrait; // Helper trait

    public static function register($email)
    {
        $account = new self();

        //...

        $account->pushEvent(new AccountRegistrationEvent($account));
        
        // Checked single event
        $account->pushSingleEvent(new MyEvent($account));
        $account->pushSingleEvent(new MyEvent($account));

        return $account;
    }


}