How to disable a plugin on a specific client in a specific environment ?
shulard opened this issue · 6 comments
| Q | A |
|---|---|
| Bug? | no |
| New Feature? | no |
| Version | 1.13.1 |
I have some specific dev env logging features enabled in my Symfony project (full message formatter, specific log channel). In the test environment I want to fully disable the logging.
Actual Behavior
When I ran the code in test, the Symfony container can't compile because of invalid logger plugin configuration.
Expected Behavior
Since I disable the logger plugin in the test env, why is it still trying to load it ?
Steps to Reproduce
Here are the Yaml files used :
# on dev
httplug:
plugins:
logger:
logger: monolog.logger.http
formatter: http.client.full-formatter
clients:
dicom_query:
plugins:
- 'httplug.plugin.content_length'
- 'httplug.plugin.redirect'
- 'httplug.plugin.logger'# on test
httplug:
plugins:
logger:
enabled: falseI though that disabling the plugin in test will disable the plugin for all the clients but I got an error in the container regarding the plugin configuration. Also when I dump the config for my test environment I saw that the plugin is still defined in the dicom_query plugin list.
how does your default config look like? if you only mention the plugin in dev and test, then i also don't see why you would get the error.
ps: php-http/client-common#158 might come in handy for you, eventually. you are welcome to provide your inputs there, if you need different setup per environment.
You are right, if I define plugin only in dev/test I don't get any error. But I though that using enabled: false will disable the plugin even if it's activated in another part of the config.
Then I checked in the container manipulation part and there isn't any logic which filter the plugin based on that. enabled: false is "just" here to disable the plugin in the current context, not to override the defined config by disabling the plugin.
I close that issue because I misunderstood the behaviour here, but I'll take a look at the linked PR because it can be very interesting in that case.
hm, the enabled/disabled should win over other configuration imho, its rather unexpected otherwise. if you see where we got that wrong, please do a pull request. its that kind of bugfix where it might break for somebody, but the user would have to had configured enabled: false in an environment so i would think they expected something to happen from that.
The problem is that symfony merges the global config params with environment params.
So if your client is using some plugins globally but don't have them configured in current environment (same client), they will still be inherited/merged.
It's quite unexpected.
you're calling https://github.com/php-http/HttplugBundle/blob/master/src/DependencyInjection/HttplugExtension.php#L44
and then you allow partial overwriting in
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Config/Definition/BaseNode.php#L291
if i understand correctly, not allowing it, would require explicit config for each client and would not inherit anything. Wouldn't that be better ?
Hello @RiseAndCry you are totally right about the behaviour !
My main concern here is that I only wanted to disable the "logger" in test environment. I haven't found a lot of time to dig in the container logic here but I'm sure we can discover a way to allow that kind of override 😄.
I understand, but my message was more directed towards this bundle's degelopers. My proposed solution (if it's possible) should solve both our problems. And might save some headache for other users.