1. Go to this page and download the library: Download dsantang/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/ */
dsantang / domain-events example snippets
use Dsantang\DomainEvents\DomainEvent;
final class OrderSent implements DomainEvent, DeletionAware
{
public const EVENT_NAME = 'order-sent';
/**
* @var OrderId
*/
private $orderId;
/**
* @var Address
*/
private $address;
/**
* @var DateTimeImmutable
*/
private $timestamp;
public function __construct(OrderId $orderId, Address $address, DateTimeImmutable $timestamp)
{
// ...
}
/**
* This is the only interface method that needs to be implemented.
* This method should return an application-unique event name.
*/
public function getEventName(): string
{
return self::EVENT_NAME;
}
public function expelDeletionEvents(): DomainEvent
{
return new OrderDeleted();
}
// ...
}
final class Order implements EventAware
{
/**
* Use this trait to cache your domain event.
*/
use EventsRegistry;
// ...
public function send(): void
{
// Domain logic is executed.
// ...
// Once the domain transaction is completed, the event must be cached via this method call:
$this->triggeredA(new OrderSent(...));
}
// ...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.