Skip to content

[EventDispatcher] Add an interface for the ContainerAwareEventDispatcher #11870

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 1 commit into from

Conversation

Nicofuma
Copy link
Contributor

@Nicofuma Nicofuma commented Sep 6, 2014

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

Currently if a class depends on the ContainerAwareEventDispatcher it's not possible to replace it by the TraceableEventDispatcher without rewriting the class.

* @param Stopwatch $stopwatch A Stopwatch instance
* @param LoggerInterface $logger A LoggerInterface instance
*/
public function __construct(ContainerAwareEventDispatcher $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

For what override constructor here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To change the type hinting, so we are sure to have a ContainerAwareEventDispatcherInterface.

@Nicofuma Nicofuma force-pushed the ev_containerawareinterface branch from efb5fe7 to c808dfb Compare September 7, 2014 11:30
*/
public function __construct(ContainerAwareEventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null)
{
parent::__construct($dispatcher, $stopwatch, $logger);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it really necessary to implement this constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, a StopwatchInterface would solve BC causes in the future ;)

didn't see the comment for some reason

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But a such interface does not exist and I'm not sure that it's in the scope of this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Then I stand by my question, is it really necessary to implement then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The goal here is not to prevent BC but to prevent the use of this class with an instance of EventDispatcherInterface instead of an instance of ContainerAwareEventDispatcherInterface (or we could throw a Fatal error late and "randomly" at the runtime)

@jakzal
Copy link
Contributor

jakzal commented Sep 13, 2014

Currently if a class depends on the ContainerAwareEventDispatcher it's not possible to replace it by the TraceableEventDispatcher without rewriting the class.

Why would you want a class to depend on the ContainerAwareEventDispatcher instead of the EventDispatcherInterface?

@Nicofuma
Copy link
Contributor Author

Each time a service is registered as a listener/subscriber but without using a compiler pass.

@Nicofuma
Copy link
Contributor Author

(And this case can happen often because the RegisterListenersPass was added only in 2.5)

@stof
Copy link
Member

stof commented Sep 13, 2014

@Nicofuma the RegisterListenersPass was already there in previous version, just in a different component.
and registering services lazily at a different time than when building the container looks weird IMO

@Nicofuma
Copy link
Contributor Author

@stof Thanks, I didn't find it in the HttpKernel component...

@jakzal
Copy link
Contributor

jakzal commented Sep 13, 2014

Each time a service is registered as a listener/subscriber but without using a compiler pass.

Could you tell us what would be an use case for this?

@Nicofuma
Copy link
Contributor Author

I sent the PR to fix this mistake in phpBB so...
To try to save this PR I could talk about the design and the ability to identity the lazy loaded listeners from the others but... I'm not sure that's a very valid argument in this case :)

@linaori
Copy link
Contributor

linaori commented Sep 13, 2014

By adding listeners on run time, it makes it unreliable when checking registered listeners using app/console container:debug --tag=kernel.event_listener for example.

@stof
Copy link
Member

stof commented Sep 13, 2014

and when adding listeners are runtime, registering services lazily is porbably less important

*
* @author Tristan Darricau <tristan@darricau.eu>
*
* @api
Copy link
Member

Choose a reason for hiding this comment

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

The @api tag must be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@Nicofuma Nicofuma force-pushed the ev_containerawareinterface branch from c808dfb to d7718dc Compare September 23, 2014 14:45
* Defaults to 0.
*
* @throws \InvalidArgumentException
* @see ContainerAwareEventDispatcherInterface::addListenerService
Copy link
Member

Choose a reason for hiding this comment

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

should be @{inheritdoc} instead.

@fabpot
Copy link
Member

fabpot commented Sep 26, 2014

@Nicofuma Can you share a URL discussing the issue for phpBB?

@Nicofuma
Copy link
Contributor Author

@fabpot It hasn't been discussed properly speaking because I discovered it while testing some of my PR together and I fixed it in phpbb/phpbb#2948 after the first comment of Stof.

@Nicofuma Nicofuma force-pushed the ev_containerawareinterface branch from d7718dc to 5a51ef8 Compare September 26, 2014 10:35
@Nicofuma Nicofuma force-pushed the ev_containerawareinterface branch from 5a51ef8 to ef3d6bd Compare September 26, 2014 10:38
@fabpot
Copy link
Member

fabpot commented Sep 26, 2014

So, does this PR still make sense?

@Nicofuma
Copy link
Contributor Author

It's the question I asked before, and because I don't know if it still make sense (currently I see one use case for that: be able to identify the lazy loaded listeners in a TraceableEventDIspatcher) I kept updating it. So feel free to close it if you want.

@fabpot
Copy link
Member

fabpot commented Sep 26, 2014

Ok, I'm closing it for now.

@fabpot fabpot closed this Sep 26, 2014
@stof
Copy link
Member

stof commented Sep 26, 2014

being able to identify lazy-loaded listeners in the TraceableEventDispatcher does not need this once #12019 is merged (we could have a way to identify them)

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