Dumplie\SharedKernel\Domain\Exception\UnknownEventException::unexpected PHP Method

unexpected() public static method

public static unexpected ( string $expectedName, string $receivedName ) : UnknownEventException
$expectedName string
$receivedName string
return UnknownEventException
    public static function unexpected(string $expectedName, string $receivedName) : UnknownEventException
    {
        throw new self(sprintf("Expected event \"%s\" but got \"%s\"", $expectedName, $receivedName));
    }

Usage Example

Exemplo n.º 1
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'])));
 }
UnknownEventException