/** * @param PropertyInterface $property */ public function add(Property $property) { if ($this->properties->containsKey($property->name())) { throw new \LogicException('There already is a property with name ' . $property->name()); } $this->properties->set($property->name(), $property); }
/** * @param string $nameOfMessage * @param object $handler */ public function addHandler($nameOfMessage, $handler) { if (!is_string($nameOfMessage)) { throw new \InvalidArgumentException(sprintf('Expected an string as a name of message. Instance of %s given', is_object($nameOfMessage) ? get_class($nameOfMessage) : gettype($nameOfMessage))); } if (!is_object($handler)) { throw new \InvalidArgumentException(sprintf('Expected an object as handler. Instance of %s given', gettype($handler))); } $this->handlers->set($nameOfMessage, $handler); }
/** * {@inheritdoc} */ public function persist(Snapshot $snapshot, Version $applicationVersion) { $applicationKey = $this->getApplicationKey($applicationVersion); if (!$this->store->containsKey($applicationKey)) { $this->store->set($applicationKey, new ArrayHashMap()); } /** @var ArrayHashMap $applicationCollection */ $applicationCollection = $this->store->get($applicationKey); $aggregateKey = $this->getAggregateKey($snapshot->aggregateType(), $snapshot->version()); if (!$applicationCollection->containsKey($aggregateKey)) { $applicationCollection->set($aggregateKey, new ArrayHashMap()); } /** @var ArrayHashMap $aggregateCollection */ $aggregateCollection = $applicationCollection->get($aggregateKey); $aggregateCollection->set($snapshot->aggregateId()->toNative(), $snapshot); }
/** * {@inheritdoc} */ public function addListener($eventName, callable $listener, $priority = 0) { if (!$this->listeners->containsKey($eventName)) { $this->listeners->set($eventName, new SortedArrayHashMap([], new ReverseComparator(new Comparator()))); } /** @var SortedArrayHashMap $sortedListeners */ $sortedListeners = $this->listeners->get($eventName); if (!$sortedListeners->containsKey($priority)) { $sortedListeners->set($priority, new ArrayList()); } $sortedListeners->get($priority)->add(new DelegateListener($listener)); }
/** * {@inheritdoc} */ public function persist(EventStream $eventStream, Version $aggregateVersion, Version $applicationVersion) { $applicationKey = $this->getApplicationKey($applicationVersion); if (!$this->store->containsKey($applicationKey)) { $this->store->set($applicationKey, new ArrayHashMap()); } /** @var ArrayHashMap $applicationCollection */ $applicationCollection = $this->store->get($applicationKey); $streamKey = $this->getStreamKey($eventStream->streamName(), $aggregateVersion); if (!$applicationCollection->containsKey($streamKey)) { $applicationCollection->set($streamKey, new ArrayHashMap()); } /** @var ArrayHashMap $streamCollection */ $streamCollection = $applicationCollection->get($streamKey); $aggregateKey = $eventStream->aggregateId()->toNative(); if (!$streamCollection->containsKey($aggregateKey)) { $streamCollection->set($aggregateKey, new ArrayList()); } /** @var ArrayList $aggregateIdCollection */ $aggregateIdCollection = $streamCollection->get($aggregateKey); foreach ($eventStream->events() as $event) { $aggregateIdCollection->add($event); } }
/** * {@inheritdoc} */ public function set($key, $value) { parent::set($key, $value); $this->sort(); }
/** * @param Version $applicationVersion */ public function persistApplicationVersion(Version $applicationVersion) { $this->store->set(self::APPLICATION_VERSION_KEY, $applicationVersion); }