public function validateLock(AggregateRootInterface $aggregate) { if (array_key_exists($aggregate->getIdentifier(), $this->locks)) { $lock = $this->locks[$aggregate->getIdentifier()]; return $lock->validate($aggregate); } return true; }
public function add(AggregateRootInterface $object) { $aggregateId = $object->getIdentifier(); $this->lockManager->obtainLock($aggregateId); try { parent::add($object); } catch (\Exception $ex) { $this->lockManager->releaseLock($aggregateId); throw $ex; } }
protected function validateOnLoad(AggregateRootInterface $object, $expectedVersion) { if (null !== $expectedVersion && null !== $object->getVersion() && $expectedVersion !== $object->getVersion()) { throw new ConflictingAggregateVersionException($object->getIdentifier(), $expectedVersion, $object->getVersion()); } }
protected function doSaveWithLock(AggregateRootInterface $aggregate) { $this->store[$aggregate->getIdentifier()] = $aggregate; $this->saveCount++; }
private function validateIdentifier($aggregateIdentifier, AggregateRootInterface $aggregate) { if (null !== $aggregateIdentifier && !$aggregateIdentifier === $aggregate->getIdentifier()) { throw new \RuntimeException(sprintf("The aggregate used in this fixture was initialized with an identifier different than " . "the one used to load it. Loaded [%s], but actual identifier is [%s].\n" . "Make sure the identifier passed in the Command matches that of the given Events.", $aggregateIdentifier, $aggregate->getIdentifier())); } }