Пример #1
0
 /**
  * @param  EventInterface $event
  * @return array
  */
 public function serialize(EventInterface $event)
 {
     $payload = $event->getPayload();
     foreach ($payload as $key => &$value) {
         if ($value instanceof Uuid) {
             $value = ['_php_class' => Uuid::class, '_value' => (string) $value];
         }
         if ($value instanceof DateTime) {
             $value = ['_php_class' => DateTime::class, '_value' => $value->format(DateTime::ISO8601)];
         }
     }
     return ['class' => get_class($event), 'id' => (string) $event->getId(), 'name' => $event->getName(), 'timestamp' => $event->getTimestamp()->format(DateTime::ISO8601), 'payload' => $payload];
 }
Пример #2
0
 /**
  * @param  EventInterface $event
  * @return void
  */
 protected function executeEvent(EventInterface $event)
 {
     $name = $event->getName();
     $method = sprintf('apply%s', ucfirst($name));
     if (!method_exists($this, $method)) {
         throw new \LogicException(sprintf("AR does not contain method '%s' needed for event '%s' to be handled.", $method, $name));
     }
     $this->{$method}($event);
 }