Fixes issue 94 by introducing a new series of classes, EventContext and the immutable EventContextData.
EventContext contains EventContextData, as well as information about the event (event name and matching pattern for this event). handleEvent is now expected to accept only EventContext and must return it; publish expects now an event name and a EventContextDataContainer instance and returns the EventContextDataContainer.
public static function handleEvent(Game $g, EventContext $context): EventContext
{
if ($context->getEvent() === "h/lotgd/core/default-scene") {
if (!$context->hasDataType(NewViewpoint::class)) {
throw new \Exception(sprintf(
"Context was expected to be %s, %s instead.",
NewViewpoint::class,
get_class($context->getData())
));
}
$context->setDataField("scene", $g->getEntityManager()->getRepository(Scene::class)->find(1));
}
return $context;
}
Fixes issue 94 by introducing a new series of classes, EventContext and the immutable EventContextData.
EventContext contains EventContextData, as well as information about the event (event name and matching pattern for this event).
handleEvent
is now expected to accept onlyEventContext
and must return it;publish
expects now an event name and aEventContextDataContainer
instance and returns theEventContextDataContainer
.Examples: