Skip to content
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

Question: way to trigger a specific function when bindings are updated #146

Closed
moufmouf opened this issue Dec 11, 2015 · 3 comments
Closed

Comments

@moufmouf
Copy link

Hi @webmozart !

I have a specific need regarding Puli. Basically, I would like to trigger some specific code each time a binding is updated. So far, bindings can be updated when a user runs a composer update (through the Composer plugin), or through the CLI.

What I would like to do is trigger a specific action at this time (if you remember our discussion at the Paris ForumPHP, I'm trying to trigger the compilation of a container and my binding is containing a list of service definition providers).

I think the way to go is to write a Puli plugin, but I have no idea on the classes / methods I should use to trigger some code at some point. Is there any kind of event system I can tap into? Would you do it this way or am I thinking the wrong way?

@webmozart
Copy link
Member

Hi @moufmouf! Yes, the way to go is with a plugin. The activation of plugins will be simplified with #144. Also, we need to add the events you need. Right now, not many events have been added to Puli's core yet. You can check the currently available events in https://github.com/puli/manager/blob/master/src/Api/Event/PuliEvents.php.

@moufmouf
Copy link
Author

@webmozart Thanks for the quick answer!

Looking at the PuliEvents.php file, I saw there is a PuliEvents::GENERATE_FACTORY event.
It seems fired in the FactoryManagerImpl::generateFactoryClass method, which is triggered from the refereshFactoryClass method. See: https://github.com/puli/manager/blob/master/src/Factory/FactoryManagerImpl.php#L235-L237

Since the factory seems refreshed each time the configuration changes, I guess I could listen to this event to listen for changes in the bindings. Am I correct? If so, we can close this issue!

@webmozart
Copy link
Member

I can't guarantee that this event will always be triggered when bindings are updated, but for the forseeable future that should remain true. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants