Skip to content

Commit

Permalink
create methods EventListenerPass::registerListeners() and EventListen…
Browse files Browse the repository at this point in the history
…erPass::registerSubscribers()
  • Loading branch information
peter-gribanov committed Oct 3, 2017
1 parent 7ae8bf6 commit 83de4e8
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/DependencyInjection/Compiler/EventListenerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

class EventListenerPass implements CompilerPassInterface
{
Expand All @@ -27,17 +28,32 @@ public function process(ContainerBuilder $container)
$symfony_locator = $container->findDefinition('domain_event.locator.symfony');
$container_locator = $container->findDefinition('domain_event.locator.container');

if ($current_locator !== $symfony_locator && $current_locator !== $container_locator) {
return;
if ($current_locator === $symfony_locator || $current_locator === $container_locator) {
$this->registerListeners($container, $current_locator);
$this->registerSubscribers($container, $current_locator);
}
}

/**
* @param ContainerBuilder $container
* @param Definition $current_locator
*/
private function registerListeners(ContainerBuilder $container, Definition $current_locator)
{
foreach ($container->findTaggedServiceIds('domain_event.listener') as $id => $attributes) {
foreach ($attributes as $attribute) {
$method = !empty($attribute['method']) ? $attribute['method'] : '__invoke';
$current_locator->addMethodCall('registerService', [$attribute['event'], $id, $method]);
}
}
}

/**
* @param ContainerBuilder $container
* @param Definition $current_locator
*/
private function registerSubscribers(ContainerBuilder $container, Definition $current_locator)
{
foreach ($container->findTaggedServiceIds('domain_event.subscriber') as $id => $attributes) {
$subscriber = $container->findDefinition($id);
$current_locator->addMethodCall('registerSubscriberService', [$id, $subscriber->getClass()]);
Expand Down

0 comments on commit 83de4e8

Please sign in to comment.