PHP code example of antismok / domain-events-publisher
1. Go to this page and download the library: Download antismok/domain-events-publisher 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/ */
antismok / domain-events-publisher example snippets
//....
use Antismok\DomainEventPublisher\DomainEvent;
class UserRegistered implements DomainEvent
{
private $occurredOn;
/**
* @var string $user
*/
private $userName;
/**
* @param string $userName
*/
function __construct(string $userName)
{
$this->useName = $userName;
$this->occurredOn = new DateTime();
}
public function username(): string
{
return $this->username;
}
public function occurredOn(): DateTime
{
return $this->occurredOn;
}
}
//....
class UserRegisteredHandler
{
public function handle(UserCreated $event)
{
//Some operation
}
}
//....
//Some config place
DomainEventPublisher::getInstance()->addListener(UserRegistered::class, [new UserRegisteredHandler, 'handle']);
//Some domain place
DomainEventPublisher::getInstance()->publish(new UserRegistered('Roman'));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.