/** * @param Uuid $id * @return User * @throws ObjectNotFoundException */ public function getUser(Uuid $id) { $user = $this->storage->find($id->getValue()); if ($user == null) { throw new ObjectNotFoundException('User', $id); } return $user; }
/** * @param Uuid $id * @return Book * @throws ObjectNotFoundException */ public function getBook(Uuid $id) { $book = $this->storage->find($id->getValue()); if ($book === null) { throw new ObjectNotFoundException('Book', $id); } return $book; }
/** * @param string $objectName * @param Uuid $objectId */ public function __construct($objectName, Uuid $objectId) { parent::__construct(sprintf(static::$messageTemplate, $objectName, $objectId->getValue())); }
/** * @param Uuid $aggregateId * @return Events * @throws AggregateNotFoundException */ public function getEventsForAggregate(Uuid $aggregateId) { if (!$this->storage->contains($aggregateId->getValue())) { throw new AggregateNotFoundException($aggregateId); } $eventsData = $this->storage->find($aggregateId->getValue()); $events = array_map(function (EventDescriptor $eventData) { return $this->serializer->deserialize($eventData->getPayload(), $this->eventMap->getClassByEventName($eventData->getEvent()), 'json'); }, $eventsData); return new Events($events); }
/** * @param Uuid $bookId */ public function __construct(Uuid $bookId) { parent::__construct(sprintf(static::$messageTemplate, $bookId->getValue())); }