-
Notifications
You must be signed in to change notification settings - Fork 53
Added PluginClientBuilder #40
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
Conversation
{ | ||
$cachePlugin = null; | ||
foreach ($this->plugins as $i => $plugin) { | ||
if ($plugin instanceof Plugin\CachePlugin) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth adding an interface plugins can implement to say they need to get pushed back instead of hard coding the cache plugin like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I like the idea. Plugins should not be affected by external configuration logic. Also, there is no guarantee that cache should always be "pushed back".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather use append/prependPlugin methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we find a way to make replace preserve the order, we would not need this.
I agree with all your comments. I created this by extracting logic from the KnpGithub client. I'll adapt to your feedback to make this generic. |
okay, the knp example is a very good illustration where this builder approach works very well. some braindump trying to figure out what we should do: in a symfony context, a compiler pass to replace services with other services would be much cleaner, and would allow to leverage the configuration options on httplug bundle. but that would mean you need a way to set up the library without framework, and a different set up for each framework integration. the thing i don't like on the knp library is that Client is a mix of an api client and a http client builder. your refactoring pushes it even more in that direction. with symfony, we would be able to change the list of plugins in a compiler pass at container build time (aka only on cache rebuild). with the builder in php, instances are created, some potentially only to be discarded later. is it the idea of that library that you would change the http setup while communicating with github? as dev, i would prefer several client instances if i need different http behaviour for different tasks, like using different credentials. its way to easy otherwise to mix things up and use the wrong settings. my idea would be that for a frameworkagnostic library, you have a builder (or whatever) that gives you the github client instance, shuffling around plugins. but for symfony, it would make more sense to not use that and have a compiler pass to manipulate the plugins of the client service that is specified in the configuration. this could get hairy when several bundles use the same client, for example the default client, but would be more efficient to instantiate the client, and easier for the user to configure. |
while preparing the web summer camp tutorial, i had a completely different idea: what if the HttplugBundle would offer a method that accepts a client configuration as the bundle config would do it, and returns a service definition? then a bundle could do its own configuration with extra plugins and whatnot and then add the plugin configuration/services it needs, do custom validation or whatever and still get a properly set up service. this approach would be specific to symfony - as are bundles in general. for other frameworks, we would need to find an approach suitable for those frameworks. but maybe its better to have framework integration framework specific? |
Since we have #71 and a plan for php-http/HttplugBundle#109, I think we could close this PR. |
What's in this PR?
This is a plugin builder that could be use to build up a Plugin client. See example usage: https://github.com/Nyholm/php-github-api/blob/plugin-client-builder/lib/Github/Client.php
Why?
Checklist
To Do
This PR needs some work but I wanted to share this code