EventSourcedRootEntityのメモ
<?php
trait EventSourcedRootEntity
{
/**
* @var DomainEvent[]
*/
private $mutatingEvents = [];
public function apply(DomainEvent $event)
{
$this->mutatingEvents[] = $event;
$this->mutateWhen($event);
}
private function mutateWhen(DomainEvent $domainEvent)
{
$eventType = (new \ReflectionClass($domainEvent))->getShortName();
$mutatorMethodName = 'when'.$eventType;
if (method_exists($this, $mutatorMethodName) === false) {
throw new \RuntimeException(
sprintf("Method %s() does not exist", $mutatorMethodName)
);
}
try {
$mutatorMethod = new \ReflectionMethod($this, $mutatorMethodName);
$mutatorMethod->setAccessible(true);
$mutatorMethod->invoke($this, $domainEvent);
} catch (\ReflectionException $e) {
throw new \RuntimeException(
sprintf("Method %s() failed", $mutatorMethodName), null, $e
);
}
}
}
Author And Source
この問題について(EventSourcedRootEntityのメモ), 我々は、より多くの情報をここで見つけました https://qiita.com/suin/items/b3d0dfa582a3461bc47e著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .