Skip to content

Commit

Permalink
Merge pull request #6 from pauci/feature/doctrine-event-manager
Browse files Browse the repository at this point in the history
feat: Retrieve doctrine event-manager directly instead through entity…
  • Loading branch information
pauci authored Jan 17, 2022
2 parents f057be4 + 28fa9d1 commit 5b92819
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/EventPublisherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use CQRS\EventHandling\Publisher\DomainEventQueue;
use CQRS\EventHandling\Publisher\EventPublisherInterface;
use CQRS\EventHandling\Publisher\SimpleEventPublisher;
use Doctrine\Common\EventManager;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Container\ContainerInterface;

/**
Expand All @@ -15,7 +15,7 @@
* event_bus: string,
* identity_map: string,
* event_store: string,
* entity_manager: string
* event_manager: string
* }
* @phpstan-extends AbstractFactory<EventPublisherInterface>
*/
Expand Down Expand Up @@ -50,14 +50,13 @@ public function createWithConfig(ContainerInterface $container, string $configKe
);

if ($eventPublisher instanceof EventSubscriber) {
$entityManager = $this->retrieveService(
$eventManager = $this->retrieveService(
$container,
$config,
'entity_manager',
EntityManagerInterface::class
'event_manager',
EventManager::class
);
$entityManager->getEventManager()
->addEventSubscriber($eventPublisher);
$eventManager->addEventSubscriber($eventPublisher);
}

return $eventPublisher;
Expand All @@ -73,7 +72,7 @@ protected function getDefaultConfig(): array
'event_bus' => 'cqrs_default',
'identity_map' => 'cqrs_default',
'event_store' => 'cqrs_default',
'entity_manager' => 'doctrine.entity_manager.orm_default',
'event_manager' => 'doctrine.event_manager.orm_default',
];
}
}

0 comments on commit 5b92819

Please sign in to comment.