/** * Set the event id * * @param EventId $eventId the event id * @throws EventException - on event type mismatch */ private function setEventId(EventId $eventId) { $eventType = $eventId->eventType(); if ($eventType != underscore($this)) { throw EventException::invalidType($eventType); } $this->eventId = $eventId; }
/** * Parse a string into an id * * @param string $eventId the string to parse * @return EventId * @throws InvalidArgumentException when the string format is invalid */ public static function fromString($eventId) { $parts = explode('_', $eventId); if (count($parts) != 3) { throw EventException::invalidId($eventId); } $id = new static($parts[0]); $id->time = (double) $parts[1]; $id->hash = (string) $parts[2]; return $id; }
/** * @param string $anEventType * @throws InvalidEventTypeException */ protected function guardEventType($anEventType) { if (!$this->isValidEventType($anEventType)) { throw EventException::invalidType($anEventType); } }
/** * Protects against invalid event types * * @param string $anEventType the event type to verify * @throws EventException - on invalid event type */ protected function guardValidEventType($anEventType) { if (!static::validateEventType($anEventType)) { throw EventException::invalidType($anEventType); } }