Inheritance: extends Exception
Exemple #1
0
 /**
  * @param Event $event
  * @return string
  * @throws UnknownEventException
  */
 private function serizlize(Event $event)
 {
     if ($event instanceof CustomerPlacedOrder) {
         return json_encode(['name' => Events::CUSTOMER_PLACED_ORDER, 'order_id' => $event->orderId(), 'date' => $event->date()->format('Y-m-d H:i:s')]);
     }
     throw UnknownEventException::unsupported(get_class($event));
 }
Exemple #2
0
 /**
  * @param string $eventJson
  * @throws UnknownEventException
  */
 public function on(string $eventJson)
 {
     $data = json_decode($eventJson, true);
     if (!array_key_exists('name', $data) || $data['name'] !== Events::CUSTOMER_PLACED_ORDER) {
         throw UnknownEventException::unexpected(Events::CUSTOMER_PLACED_ORDER, $data['name']);
     }
     $this->orders->add(new Order(new OrderId($data['order_id']), new \DateTimeImmutable($data['date'])));
 }