Skip to content

Instantly share code, notes, and snippets.

@nicholasruunu
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholasruunu/d29ba4719d7ba89bc8b3 to your computer and use it in GitHub Desktop.
Save nicholasruunu/d29ba4719d7ba89bc8b3 to your computer and use it in GitHub Desktop.
DomainEventProxy trait exmple
<?php
trait DomainEventProxy
{
private $eventMethodMapping = [];
private function callMappedMethod(DomainEvent $event, ...$arguments)
{
$method = $this->resolveMethod($event);
$this->$method($event, ...$arguments);
}
private function resolveMethod(DomainEvent $event)
{
$eventName = (new ReflectionClass($event))->getShortName();
if (!array_key_exists($eventName, $this->eventMethodMapping)) {
throw Exception("$eventName has not been mapped.");
}
return $this->eventMethodMapping[$eventName];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment