-
Notifications
You must be signed in to change notification settings - Fork 50
Configure plugins #37
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
I'm having second thoughts about this. It would mean that a Symfony installation that does not have Monolog would get an error like "httplug.plugin.logger has a dependency on a service 'logger'. No such service found". I guess that it would be less "magic" if we removed it and let the user configure the logger like any other plugin with dependencies. |
Maybe we can also enabled the stopwatch plugin based on the kernel.debug value by default ? |
Same problem there as with the logger. What if the stopwatch service does not exist? |
I've updated the PR. The logger is not treated any special |
I don't think this is too much of a problem, we can just throw an exception if service is not available. IMO if someone have desactived the stopwatch and log service in his debug mode / application he will know how to change the configuration :) |
What if we only enable them automatically if:
|
hm, sure. I can give the logging plugin and the stopwatch plugin its dependencies in a compiler pass (if the dependency services exists). That would make sense. |
->arrayNode('authentication') | ||
->canBeEnabled() | ||
->children() | ||
->scalarNode('authentication')->isRequired()->cannotBeEmpty()->end() |
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.
can we add an info to this? this is the name of the authentication service that implements some php-http interface?
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.
Added info() on all nodes that require a service.
cool! i like the idea with the compiler pass. we could say: if explicitly disabled, we remove the service definition in the di class. if explicitly enabled, we somehow tell the compiler pass to explode if stopwatch/logger are not available. the default behaviour should be that if the requirements are met, we enable those plugin, otherwise we automatically disable them. would need some container parameter i fear. and injecting the optoinal plugins to the client services in the compiler pass. hm. which will lead to priorisation challenges. |
I might be able to do it without ana container parameters. I'll give it some thoughts after work. |
* @param ContainerBuilder $container | ||
* @param array $config | ||
*/ | ||
protected function configurePlugins(ContainerBuilder $container, array $config) |
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.
why not private?
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.
Fixed!
4389dfe
to
79c85d5
Compare
@dbu mentioned an issue in #37 (comment)
First of, we do not use You do highlight the fact that the following two way of using the cache plugins are exactly the same: Option A) // config.yml
httplug:
plugins:
cache:
cache_pool: 'cache'
clients:
acme:
factory: 'httplug.factory.guzzle6'
plugins: ['httplug.plugin.cache'] Option B) // services.yml
services:
my_cache_plugin:
class: Http\Client\Plugin\CachePlugin
arguments: ["@cache"] // config.yml
httplug:
clients:
acme:
factory: 'httplug.factory.guzzle6'
plugins: ['my_cache_plugin'] B is the generic approach that will always work and is suggested that you do with your custom made plugins. A makes much more sense for plugins like decoder, retry and redirect because they only have scalar dependencies. In fact, option B would be unnecessarily complicated for such plugins. I believe that we should allow these two options for configuring all plugins because it would be weird to support option A for only a subset of our plugins. |
515cd74
to
84f5ae4
Compare
if (!$container->hasDefinition('debug.stopwatch')) { | ||
$container->removeDefinition('httplug.plugin.stopwatch'); | ||
} | ||
} |
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.
With this compiler pass we make sure that the exception messages makes sense.
Before:
If logger plugin was or wasn't used and logger
is not defined you would get an exception like "httplug.plugin.logger" requested an non existing service 'logger'".
Now:
If logger plugin is used and logger
is missing you will get an exception like "httplug.client.acme has requested an non existing service 'httplug.plugin.logger'"
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.
hm, i wonder if we could instead detect the problem in the compiler pass and throw the exception "to use the logger plugin, you need to have a logger service configured"
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.
That would require us to know what plugins that are being used. We have currently no clue about that in the compiler pass. It could be solved with container parameters or a DebugPluginClient::getPlugins().
You could also make an argument that the very few users that have logger/stopwatch disabled probably knows about it and are skilled enough to figure out that the LoggerPlugin requires a logger. But now I am making assumptions based on no facts.
okay, agree on consistency and allowing to configure all standard plugins. |
Im happy to say that I was wrong. If, however, I use the logging plugin (still with no
// config.yml
httplug:
clients:
acme:
factory: 'httplug.factory.guzzle6'
plugins: ['httplug.plugin.logger'] No compiler pass needed =) |
307f2b0
to
7e5816f
Compare
looks good! |
@dbu, I have addressed all the comments and feedback. I think this is ready to merge. |
Do you think we can tag a new release after this PR? Either 1.0 or a new MJZ. I don't want to rush with the stable if you think there is more work to be done. |
I do not think this is ready for a stable release yet. There are some changes that we want to do on the issue tracker. Also, I have not been running this in production yet. I want to make sure it is no major bugs and that concept/API/config makes sense when adding more third party bundles. |
Okay. Although I already use it in production 😄 |
thanks a lot! i created #38 for the release discussion |
This PR fixes #17
This make sure that you can configure all our 9 configurable plugins. Some plugins (like
RetryPlugin
) has only optional configuration. They are enabled by default. They others are disabled by default.Also, the
LoggerPlugin
is treated special. We inject thelogger
service automatically and it is enabled by default. This is done because of ease of use.