Skip to content

Commit

Permalink
Merge pull request #258 from neos/bugfix/deterministic-defaultEventPu…
Browse files Browse the repository at this point in the history
…blisherFactory

BUGFIX: Make DefaultEventPublisherFactory return the same instance
  • Loading branch information
bwaidelich committed Feb 3, 2020
2 parents 732538d + 00a803c commit 75ee50e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Classes/EventPublisher/DefaultEventPublisherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,24 @@ final class DefaultEventPublisherFactory implements EventPublisherFactoryInterfa
*/
private $mappingProvider;

/**
* A list of all initialized Event Publisher instances, indexed by the "Event Store identifier"
*
* @var EventPublisherInterface[]
*/
private $eventPublisherInstances;

public function __construct(DefaultEventToListenerMappingProvider $mappingProvider)
{
$this->mappingProvider = $mappingProvider;
}

public function create(string $eventStoreIdentifier): EventPublisherInterface
{
$mappings = $this->mappingProvider->getMappingsForEventStore($eventStoreIdentifier);
return DeferEventPublisher::forPublisher(new JobQueueEventPublisher($eventStoreIdentifier, $mappings));
if (!isset($this->eventPublisherInstances[$eventStoreIdentifier])) {
$mappings = $this->mappingProvider->getMappingsForEventStore($eventStoreIdentifier);
$this->eventPublisherInstances[$eventStoreIdentifier] = DeferEventPublisher::forPublisher(new JobQueueEventPublisher($eventStoreIdentifier, $mappings));
}
return $this->eventPublisherInstances[$eventStoreIdentifier];
}
}

0 comments on commit 75ee50e

Please sign in to comment.