Skip to content

Commit

Permalink
Subscribe to doctrine events using configuration instead of factory code
Browse files Browse the repository at this point in the history
  • Loading branch information
pauci committed May 25, 2017
1 parent 4281c24 commit 8556c72
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"require": {
"php": "^7.0",
"psr/container": "^1.0",
"pauci/cqrs": "^0.3.1"
"pauci/cqrs": "^0.3.3"
},
"require-dev": {
"phpunit/phpunit": "^5.1",
Expand Down
13 changes: 11 additions & 2 deletions example/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
'event_bus' => 'cqrs_default',
'identity_map' => 'cqrs_default',
'event_store' => 'cqrs_default',
'entity_manager' => 'doctrine.entity_manager.orm_default',
],
],

Expand All @@ -45,7 +44,6 @@
'identity_map' => [
'cqrs_default' => [
'class' => CQRS\Plugin\Doctrine\EventHandling\Publisher\DoctrineIdentityMap::class,
'entity_manager' => 'doctrine.entity_manager.orm_default',
],
],

Expand All @@ -67,4 +65,15 @@
'App\Model\Entity\Event\OriginalEvent' => CQRSFactory\Event\RenamedEvent::class,
],
],

'doctrine' => [
'event_manager' => [
'orm_default' => [
'subscribers' => [
'cqrs.event_publisher.cqrs_default',
'cqrs.identity_map.cqrs_default',
],
],
],
],
];
8 changes: 0 additions & 8 deletions src/EventPublisherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use CQRS\EventHandling\Publisher\DomainEventQueue;
use CQRS\EventHandling\Publisher\EventPublisherInterface;
use CQRS\EventHandling\Publisher\SimpleEventPublisher;
use CQRS\Plugin\Doctrine\EventHandling\Publisher\DoctrineEventPublisher;
use Psr\Container\ContainerInterface;

class EventPublisherFactory extends AbstractFactory
Expand Down Expand Up @@ -40,12 +39,6 @@ public function createWithConfig(ContainerInterface $container, string $configKe
)
);

if ($eventPublisher instanceof DoctrineEventPublisher) {
$container->get($config['entity_manager'])
->getEventManager()
->addEventSubscriber($eventPublisher);
}

return $eventPublisher;
}

Expand All @@ -59,7 +52,6 @@ protected function getDefaultConfig(): array
'event_bus' => 'cqrs_default',
'identity_map' => 'cqrs_default',
'event_store' => 'cqrs_default',
'entity_manager' => 'doctrine.entity_manager.orm_default',
];
}
}
8 changes: 0 additions & 8 deletions src/IdentityMapFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use CQRS\EventHandling\Publisher\IdentityMapInterface;
use CQRS\EventHandling\Publisher\SimpleIdentityMap;
use CQRS\Plugin\Doctrine\EventHandling\Publisher\DoctrineIdentityMap;
use Psr\Container\ContainerInterface;

class IdentityMapFactory extends AbstractFactory
Expand All @@ -18,12 +17,6 @@ protected function createWithConfig(ContainerInterface $container, string $confi
{
$config = $this->retrieveConfig($container, $configKey, 'identity_map');

if ($config['class'] === DoctrineIdentityMap::class) {
return new DoctrineIdentityMap(
$container->get($config['entity_manager'])
);
}

return new $config['class'];
}

Expand All @@ -34,7 +27,6 @@ protected function getDefaultConfig(): array
{
return [
'class' => SimpleIdentityMap::class,
'entity_manager' => 'doctrine.entity_manager.orm_default',
];
}
}

0 comments on commit 8556c72

Please sign in to comment.