private function detectIllegalStateChanges() { if (null !== $this->aggregateIdentifier && null !== $this->workingAggregate && $this->reportIllegalStateChange) { $uow = DefaultUnitOfWork::startAndGet(); try { $aggregate2 = $this->repository->load($this->aggregateIdentifier); if ($this->workingAggregate->isDeleted()) { throw new GovernorAssertionError("The working aggregate was considered deleted, " . "but the Repository still contains a non-deleted copy of " . "the aggregate. Make sure the aggregate explicitly marks " . "itself as deleted in an EventHandler."); } $this->assertValidWorkingAggregateState($aggregate2); } catch (AggregateNotFoundException $notFound) { if (!$this->workingAggregate->isDeleted()) { throw new GovernorAssertionError("The working aggregate was not considered deleted, " . "but the Repository cannot recover the state of the " . "aggregate, as it is considered deleted there."); } } catch (\Exception $ex) { $this->logger->warn("An Exception occurred while detecting illegal state changes in {class}.", array('class' => get_class($this->workingAggregate)), $ex); } finally { // rollback to prevent changes bing pushed to event store $uow->rollback(); } } }