Skip to content

[DoctrineBridge][EventDispatcher] Add LazyEventManager and LazyEventDispatcher #20039

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 2 commits into from

Conversation

enumag
Copy link
Contributor

@enumag enumag commented Sep 24, 2016

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

My application does not use the full symfony framework, just some parts. Among them the DoctrineBridge and EventDispatcher. I'd like to have the subscribers loaded lazily which symfony can do but the classes require a Container from Symfony\DependencyInjection - which I don't use. I'm using a different DI container, namely nette/di.

The logic of ContainerAwareEventManager/Dispatcher is not really dependent on symfony/dependency-injection. In fact the container is only used once in the whole class. Therefore I'd like to split the classes like this so that I don't have to copy the lazy-loading logic when using a different DI container.

@enumag
Copy link
Contributor Author

enumag commented Sep 24, 2016

I've refactored it a little bit. The LazyEventManager/Dispatcher is no longer abstract with a method to be implemented. Instead it accepts a callable resolver. The ContainerAwareEventManager/Dispatcher simply wrap the container into a closure.

It is cleaner this way in my opinion but I can revert it if desired.

EDIT: For reference you can find the original implementation here: https://github.com/enumag/symfony/commits/lazy-3

@enumag enumag force-pushed the lazy branch 4 times, most recently from c606588 to 490e8e0 Compare September 24, 2016 15:58
Copy link
Contributor

@lemoinem lemoinem left a comment

Choose a reason for hiding this comment

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

I like this version better too... I don't think anything in the docs need updating...

However, splitting the tests for ContainerAwareEventManageras you did for the code. And use them as a basis to write tests for the ContainerAware/LazyEventManager too?

Status: Needs work

@enumag
Copy link
Contributor Author

enumag commented Sep 28, 2016

@lemoinem Done, please review.

Status: Needs Review

@lemoinem
Copy link
Contributor

@enumag Could you rename the Lazy* Tests to mention LazyListener instead of Services?

Status: Needs work

@enumag
Copy link
Contributor Author

enumag commented Sep 28, 2016

@lemoinem There is nothing lazy about the listeners, just the evm/evd is lazy. So I'll just rename $service to $listener.

@lemoinem
Copy link
Contributor

Yes, but it is lazyily loaded. My point is, tests for the lazy evm/evd do not deal with services but lazily built/loaded listeners, so I think the test names should reflect that.

@enumag
Copy link
Contributor Author

enumag commented Sep 28, 2016

@lemoinem Like this?

EDIT: If your're talking about methods names they are named after the methods they are supposted to test.

Status: Needs Review

@lemoinem
Copy link
Contributor

Yes, I noticed this afterward. Since the Lazy evm/evd only takes a closure to lazily load the listeners, I don't think it should refer to services at all... What do you think?

@enumag
Copy link
Contributor Author

enumag commented Sep 28, 2016

@lemoinem I agree but since there is "service" in the method names I can't change it because of BC.

@lemoinem
Copy link
Contributor

Why not introduce new methods in the new class and keep (depreciate?) the current methods in the current class? The other way around would be to introduce an interface similar to PSR11's ContainerInterface within the component and make Symfony's ContainerInterface extend it... But I'm not sure it would still solve your problem...

@enumag
Copy link
Contributor Author

enumag commented Sep 28, 2016

I don't think introducing new methods is a good idea. I mean even in my case I'll still use DI container with services, just a different implementation.

PSR11 unfortunately isn't acccepted yet and creating something similar doesn't have a chance to be merged.

@lemoinem
Copy link
Contributor

OK, Then I guess keeping the current code will be good enough... Thanks.
Status: Reviewed

@enumag
Copy link
Contributor Author

enumag commented Nov 19, 2016

ping @fabpot

@fabpot
Copy link
Member

fabpot commented Nov 19, 2016

We are in a code freeze, so any new feature will be consider after the release of 3.2.

@enumag
Copy link
Contributor Author

enumag commented Nov 24, 2016

@fabpot There is a separate 3.2 branch now. I'm guessing that fulfills the requirement?

@stof
Copy link
Member

stof commented Nov 24, 2016

I'm quite -1 for adding the integration between nette/di and doctrine/common in our doctrine bridge. Our bridges are meant to provide integration between Symfony and external libraries, not between 2 libraries outside Symfony.

If you want to have a shared LazyEventManager somewhere, you should submit it to doctrine/common, not to Symfony.

@enumag
Copy link
Contributor Author

enumag commented Nov 24, 2016

@stof That's a good point! Yeah I should try and push it to doctrine/common. Here are some questions for you:

  • Can I use the implementation and tests from Symfony? What should I do with the copyright? If I can use the existing Symfony code as a base I'll gladly create such pull request to doctrine/common.
  • What do you think about the LazyEventDispatcher?

@enumag
Copy link
Contributor Author

enumag commented Dec 4, 2016

ping @stof @fabpot

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016
@nicolas-grekas
Copy link
Member

For the LazyEventDispatcher, WDYT of #20875 instead?

@nicolas-grekas
Copy link
Member

Since we're going to deprecate ContainerAwareEventDispatcher, I think this PR will be obsoleted by either #20953 or #20875.

@fabpot
Copy link
Member

fabpot commented Dec 17, 2016

Closing as we are working on a more generic way to solve this problem as mentioned by @nicolas-grekas

@fabpot fabpot closed this Dec 17, 2016
fabpot added a commit that referenced this pull request Jan 7, 2017
…t type (nicolas-grekas)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI][EventDispatcher] Add & wire closure-proxy argument type

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #12521, #12007, #20039
| License       | MIT
| Doc PR        | -

By resolving event subscribers at compile time, then wrapping listeners in a closure, we get laziness almost for free. This should solve/replaced all the above linked issues.

(WIP because tests are missing)

Commits
-------

ecdf857 [DI][EventDispatcher] Add & wire closure-proxy argument type
@enumag
Copy link
Contributor Author

enumag commented Mar 11, 2017

@fabpot @stof The LazyEventManager is still needed. I understand why you don't want it in Symfony though. Can I use the ContainerAwareEventManager implementation and tests as a base for a pull request to doctrine/common? What should I do with the copyright?

@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 2017
@sstok
Copy link
Contributor

sstok commented Apr 9, 2017

@enumag Make sure to keep the author's intact and you can propose this to the Doctrine project 👍 both are MIT licensed, so this shouldn't be a problem.

Make sure to link this pull request so they can decide if this acceptable.

@enumag
Copy link
Contributor Author

enumag commented Apr 9, 2017

@sstok Thanks, I'll look into it when I have some time.

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.

7 participants