Skip to content

[FrameworkBundle][Command] print registered event-listeners + event-subscribers #8234

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

Closed
wants to merge 6 commits into from
Closed

[FrameworkBundle][Command] print registered event-listeners + event-subscribers #8234

wants to merge 6 commits into from

Conversation

floriansemm
Copy link

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixedtickets
License MIT

New console-command for the event-dispatcher. The command prints a table like the container:debug command with all registered events and their event-listeners.
The list is sorted by events.
There is an additional argument event. If this parameter is set, the command prints the listener for the event.

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed.

@floriansemm
Copy link
Author

unittests are needed?

$class = $containerBuilder->getDefinition($id)->getClass();

$refClass = new \ReflectionClass($class);
$interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved out off loop, or even hardcoded, as it's not used anymore.

$table = $this->getHelperSet()->get('table');
$table
->setHeaders(array('Class', 'Event'))
->setLayout(TableHelper::LAYOUT_BORDERLESS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using default layout?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The table should look like the "container:debug" command

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it does not, does it?

I opened #8292 to fix that.

@lyrixx
Copy link
Member

lyrixx commented Jun 16, 2013

IMHO, you should add a big warning: You can display only "configured" listener. i.e.: You can not display listener created during the run-time. I know this is obvious, but not for every body.

{
$this
->setName('event_dispatcher:debug')
->addArgument('event', InputArgument::OPTIONAL, 'Show listeners for a event', '')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for an event

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can leave the '' last argument as it is defaulting to null also

@fabpot
Copy link
Member

fabpot commented Mar 27, 2014

closing in favor of #10388

@fabpot fabpot closed this Mar 27, 2014
fabpot added a commit that referenced this pull request Sep 15, 2014
…isplay registered listeners (matthieuauger)

This PR was merged into the 2.6-dev branch.

Discussion
----------

[FrameworkBundle] [Command] Event Dispatcher Debug - Display registered listeners

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT

------------------------------------------
[Update] The PR has been updated in order to comply with @stof comments.

Current status :
- [x] New event dispatcher Descriptor
- [x] Manage all callables
- [x] Unit tests
- [x] Text description
- [x] XML description
- [x] Json description
- [x] Markdown description

-----------------------------------------
Hi. In some big applications with lots of events, it's often hard to debug which classes listen to which events, and what is the order of theses listeners. This PR allows to run

- *event-dispatcher:debug* which displays all configured listeners + the events they listen to

![capture d cran de 2014-03-07 20 13 56](https://f.cloud.github.com/assets/1172099/2361104/40a86a62-a62d-11e3-9ccd-360a8d75b2a4.png)

- *event-dispatcher:debug* **event** which displays configured listeners for this specific event (order by priority desc)

![capture d cran de 2014-03-07 20 14 31](https://f.cloud.github.com/assets/1172099/2361100/31e0d12c-a62d-11e3-963b-87623d05642c.png)

The output is similar to *container:debug* command and is available in all supported formats (txt, xml, json and markdown).

I found another PR with same goal (#8234), but the approach looks too complicated to me plus I think we should fetch the listeners directly with the event_dispatcher.

Commits
-------

ce53c8a [FrameworkBundle] Add Event Dispatcher debug command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants