Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[FrameworkBundle] Added option to specify the event dispatcher in debug:event-dispatcher #39276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 2 src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ CHANGELOG
-----

* Added support for configuring PHP error level to log levels
* Added the `dispatcher` option to `debug:event-dispatcher`
* Added the `event_dispatcher.dispatcher` tag

5.2.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bundle\FrameworkBundle\Command;

use Psr\Container\ContainerInterface;
use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -29,14 +30,16 @@
*/
class EventDispatcherDebugCommand extends Command
{
private const DEFAULT_DISPATCHER = 'event_dispatcher';

protected static $defaultName = 'debug:event-dispatcher';
private $dispatcher;
private $dispatchers;

public function __construct(EventDispatcherInterface $dispatcher)
public function __construct(ContainerInterface $dispatchers)
{
parent::__construct();

$this->dispatcher = $dispatcher;
$this->dispatchers = $dispatchers;
}

/**
Expand All @@ -47,6 +50,7 @@ protected function configure()
$this
->setDefinition([
new InputArgument('event', InputArgument::OPTIONAL, 'An event name or a part of the event name'),
new InputOption('dispatcher', null, InputOption::VALUE_REQUIRED, 'To view events of a specific event dispatcher', self::DEFAULT_DISPATCHER),
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw description'),
])
Expand Down Expand Up @@ -74,12 +78,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io = new SymfonyStyle($input, $output);

$options = [];
$dispatcherServiceName = $input->getOption('dispatcher');
if (!$this->dispatchers->has($dispatcherServiceName)) {
$io->getErrorStyle()->error(sprintf('Event dispatcher "%s" is not available.', $dispatcherServiceName));

return 1;
}

$dispatcher = $this->dispatchers->get($dispatcherServiceName);

if ($event = $input->getArgument('event')) {
if ($this->dispatcher->hasListeners($event)) {
if ($dispatcher->hasListeners($event)) {
$options = ['event' => $event];
} else {
// if there is no direct match, try find partial matches
$events = $this->searchForEvent($this->dispatcher, $event);
$events = $this->searchForEvent($dispatcher, $event);
if (0 === \count($events)) {
$io->getErrorStyle()->warning(sprintf('The event "%s" does not have any registered listeners.', $event));

Expand All @@ -93,10 +106,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$helper = new DescriptorHelper();

if (self::DEFAULT_DISPATCHER !== $dispatcherServiceName) {
$options['dispatcher_service_name'] = $dispatcherServiceName;
}

$options['format'] = $input->getOption('format');
$options['raw_text'] = $input->getOption('raw');
$options['output'] = $io;
$helper->describe($io, $this->dispatcher, $options);
$helper->describe($io, $dispatcher, $options);

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,14 @@ protected function describeContainerEnvVars(array $envs, array $options = [])
protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = [])
{
$event = \array_key_exists('event', $options) ? $options['event'] : null;
$dispatcherServiceName = $options['dispatcher_service_name'] ?? null;

$title = 'Registered listeners';

if (null !== $dispatcherServiceName) {
$title .= sprintf(' of event dispatcher "%s"', $dispatcherServiceName);
}

if (null !== $event) {
$title .= sprintf(' for event `%s` ordered by descending priority', $event);
$registeredListeners = $eventDispatcher->getListeners($event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,19 @@ protected function describeContainerEnvVars(array $envs, array $options = [])
protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = [])
{
$event = \array_key_exists('event', $options) ? $options['event'] : null;
$dispatcherServiceName = $options['dispatcher_service_name'] ?? null;

$title = 'Registered Listeners';

if (null !== $dispatcherServiceName) {
$title .= sprintf(' of Event Dispatcher "%s"', $dispatcherServiceName);
}

if (null !== $event) {
$title = sprintf('Registered Listeners for "%s" Event', $event);
$title .= sprintf(' for "%s" Event', $event);
$registeredListeners = $eventDispatcher->getListeners($event);
} else {
$title = 'Registered Listeners Grouped by Event';
$title .= ' Grouped by Event';
// Try to see if "events" exists
$registeredListeners = \array_key_exists('events', $options) ? array_combine($options['events'], array_map(function ($event) use ($eventDispatcher) { return $eventDispatcher->getListeners($event); }, $options['events'])) : $eventDispatcher->getListeners();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class UnusedTagsPass implements CompilerPassInterface
'controller.argument_value_resolver',
'controller.service_arguments',
'data_collector',
'event_dispatcher.dispatcher',
'form.type',
'form.type_extension',
'form.type_guesser',
Expand Down Expand Up @@ -72,9 +73,9 @@ class UnusedTagsPass implements CompilerPassInterface
'routing.expression_language_provider',
'routing.loader',
'routing.route_loader',
'security.authenticator.login_linker',
'security.expression_language_provider',
'security.remember_me_aware',
'security.authenticator.login_linker',
'security.voter',
'serializer.encoder',
'serializer.normalizer',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\CallbackInterface;
use Symfony\Contracts\Cache\TagAwareCacheInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\Service\ResetInterface;
use Symfony\Contracts\Service\ServiceSubscriberInterface;
Expand Down Expand Up @@ -479,6 +480,8 @@ public function load(array $configs, ContainerBuilder $container)
->addTag('kernel.cache_clearer');
$container->registerForAutoconfiguration(CacheWarmerInterface::class)
->addTag('kernel.cache_warmer');
$container->registerForAutoconfiguration(EventDispatcherInterface::class)
->addTag('event_dispatcher.dispatcher');
$container->registerForAutoconfiguration(EventSubscriberInterface::class)
->addTag('kernel.event_subscriber');
$container->registerForAutoconfiguration(LocaleAwareInterface::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@

->set('console.command.event_dispatcher_debug', EventDispatcherDebugCommand::class)
->args([
service('event_dispatcher'),
tagged_locator('event_dispatcher.dispatcher'),
])
->tag('console.command', ['command' => 'debug:event-dispatcher'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class_exists(WorkflowEvents::class) ? WorkflowEvents::ALIASES : []
->set('event_dispatcher', EventDispatcher::class)
->public()
->tag('container.hot_path')
->tag('event_dispatcher.dispatcher')
->alias(EventDispatcherInterfaceComponentAlias::class, 'event_dispatcher')
->alias(EventDispatcherInterface::class, 'event_dispatcher')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ private function createFirewall(ContainerBuilder $container, string $id, array $

// Register Firewall-specific event dispatcher
$firewallEventDispatcherId = 'security.event_dispatcher.'.$id;
$container->register($firewallEventDispatcherId, EventDispatcher::class);
$container->register($firewallEventDispatcherId, EventDispatcher::class)
->addTag('event_dispatcher.dispatcher');

// Register listeners
$listeners = [];
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.