Skip to content

fesor/domain-events

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Domain Events

This is very simple implementation of domain events.

Usage

<?php

namespace Domain\User;
 
use \Fesor\DomainEvent\DomainEvents; 
 
class User {
    
    use DomainEvents;
    
    private $email;
    
    private $password;
    
    public function __constructor(Email $email, Password $password)
    {
        $this->email = $email;
        $this->password = $password;
        // remember event
        $this->rememberThat(new UserRegistered($this));
    }
}

Now we can know what happened with our entity during request:

$user = new User(new Email($email), new Password($password));
$events = $user->releaseEvents(); // will return array with UserRegistered event
$tryAgain = $user->releaseEvents(); // will return empty array, since we already released all events

$dispatcher = new EventDispatcher();
$dispatcher->dispatch($events);

About

Simple Domain Events Implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages