diff --git a/src/Command/DebugCommand.php b/src/Command/DebugCommand.php index f19192a..d1b279d 100644 --- a/src/Command/DebugCommand.php +++ b/src/Command/DebugCommand.php @@ -2,10 +2,13 @@ namespace BornFree\TacticianDomainEventBundle\Command; +use BornFree\TacticianDomainEvent\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\DependencyInjection\ContainerInterface; class DebugCommand extends Command { @@ -14,11 +17,36 @@ class DebugCommand extends Command */ private $mappings; - public function __construct(array $mappings) + public function __construct(ContainerInterface $container, array $listeners, array $subscribers) { parent::__construct(); - $this->mappings = $mappings; + $events = []; + + foreach ($listeners as $serviceId => $tags) { + foreach ($tags as $tag) { + $listener = $container->get($serviceId); + $method = array_key_exists('method', $tag) ? $tag['method'] : '__invoke'; + + $events[$tag['event']][] = get_class($listener) . '::' . $method; + } + } + + foreach ($subscribers as $serviceId => $tags) { + $subscriber = $container->get($serviceId); + + if (!$subscriber instanceof EventSubscriberInterface) { + continue; + } + + foreach ($subscriber->getSubscribedEvents() as $event => $method) { + $events[$event][] = get_class($subscriber) . '::' . $method[1]; + } + } + + ksort($events); + + $this->mappings = $events; } protected function configure() diff --git a/src/DependencyInjection/Compiler/PopulateDebugCommandPass.php b/src/DependencyInjection/Compiler/PopulateDebugCommandPass.php index 010df35..cc31a85 100644 --- a/src/DependencyInjection/Compiler/PopulateDebugCommandPass.php +++ b/src/DependencyInjection/Compiler/PopulateDebugCommandPass.php @@ -18,30 +18,7 @@ public function process(ContainerBuilder $container) $subscribers = $container->findTaggedServiceIds('tactician.event_subscriber'); $listeners = $container->findTaggedServiceIds('tactician.event_listener'); - $events = []; - - foreach ($listeners as $serviceId => $tags) { - foreach ($tags as $tag) { - $listener = $container->getDefinition($serviceId); - $method = array_key_exists('method', $tag) ? $tag['method'] : '__invoke'; - - $events[$tag['event']][] = $listener->getClass() . '::' . $method; - } - } - - foreach ($subscribers as $serviceId => $tags) { - $subscriber = $container->get($serviceId); - - if (!$subscriber instanceof EventSubscriberInterface) { - continue; - } - - foreach ($subscriber->getSubscribedEvents() as $event => $method) { - $events[$event][] = get_class($subscriber) . '::' . $method[1]; - } - } - - ksort($events); - $command->setArgument(0, $events); + $command->setArgument(1, $listeners); + $command->setArgument(2, $subscribers); } } diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 7e7d163..220a89e 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -2,7 +2,7 @@ services: tactician_domain_events.dispatcher: class: BornFree\TacticianDomainEvent\EventDispatcher\EventDispatcher lazy: true - + tactician_domain_events.middleware.release_recorded_events: class: BornFree\TacticianDomainEvent\Middleware\ReleaseRecordedEventsMiddleware arguments: ['@tactician_domain_events.doctrine.event_collector', '@tactician_domain_events.dispatcher'] @@ -10,5 +10,7 @@ services: tactician_domain_events.command.debug: class: BornFree\TacticianDomainEventBundle\Command\DebugCommand + arguments: + - '@service_container' tags: - { name: console.command }