protected function doLoad($id, $expectedVersion) { try { $events = $this->eventStore->readEvents($this->getTypeIdentifier(), $id); } catch (EventStreamNotFoundException $ex) { throw new AggregateNotFoundException($id, "The aggregate was not found", $ex); } foreach ($this->eventStreamDecorators as $decorator) { $events = $decorator->decorateForRead($this->getTypeIdentifier(), $id, $events); } $aggregate = $this->factory->createAggregate($id, $events->peek()); $unseenEvents = array(); $aggregate->initializeState(new CapturingEventStream($events, $unseenEvents, $expectedVersion)); if ($aggregate->isDeleted()) { throw new AggregateDeletedException($id); } CurrentUnitOfWork::get()->registerListener(new ConflictResolvingListener($aggregate, $unseenEvents, $this->conflictResolver)); return $aggregate; }