-
Notifications
You must be signed in to change notification settings - Fork 50
Add configuration option to disable registration of default client #314
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
196d9b0
to
5d05ccf
Compare
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.
thanks! i wonder if we should touch the default client or rather the alias with the client interface / class name (i think there are several, for psr-18 and http async and sync client). or we could remove both when the option is set.
@@ -87,6 +87,10 @@ public function load(array $configs, ContainerBuilder $container) | |||
$this->configureClients($container, $config); | |||
$this->configurePlugins($container, $config['plugins']); // must be after clients, as clients.X.plugins might use plugins as templates that will be removed | |||
$this->configureAutoDiscoveryClients($container, $config); | |||
|
|||
if (!$config['register_default_client']) { | |||
$container->removeDefinition('httplug.client.default'); |
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.
your goal is to prevent autowiring from happening, right? would it not be better to have an autowire_client
flag and remove the alias with the client class name instead of the default
service? with this, you would get an error that the alias is invalid, no?
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 think the difference here is Symfony 3.4 and 4+.
With Symfony 3.4: when you have a default
service, it will just auto wire when you use its class name.
I believe this changed in 4+ where you have to explicitly set the name of the service to the class name.
I faced this issue in a SF 3.4 application.
@ruudk wdyt about the questions i asked? |
Sorry for not responding. I will pick this up next week. |
please also rebase on master when you work on this. we moved the php files into src/ and tests/ i had no conflicts for other open merge requests, but github seems to not want to automatically solve this. |
5d05ccf
to
8266434
Compare
Rebased the PR and didn't apply much changes. See comment above. |
looking at https://github.com/php-http/HttplugBundle/blob/master/src/Resources/config/services.xml#L44-L45 i am a bit confused. we set the default client to be loaded from discovery if there are no clients defined at all. and then we overwrite that with HttplugBundle/src/DependencyInjection/HttplugExtension.php Lines 114 to 123 in d053921
so the configuration option would prevent both the factory service and aliasing the first client as the default client. @Nyholm do you remember why we have the factory based client service as well? so that things work if you configure no client at all? and the alias in https://github.com/php-http/HttplugBundle/blob/master/src/Resources/config/services.xml#L47 is actually on a client with |
8266434
to
2c85746
Compare
I like the feature but not the implementation (I think). David: At runtime we configure profiling to the auto discovered client if we don't got any. It is a bit messy to say the least. Me and @fbourigault spend some long hours trying to figure stuff out. @ruudk What about only removing the aliases and not the actual service? |
2c85746
to
96121b4
Compare
@Nyholm I updated the PR. It now only removes the aliases. Therefore, I think we might want to rename the configuration property to something like |
agreed, and i think register_default_client_for_autowiring is a good name. it would be can you please also rebase your pull request on master? i think we fixed the lowest build there. |
Awesome. This is a much simpler implementation 👍 |
I prefer small value :), what about: |
|
i would not call it default_autowiring. we could do |
If we want to use this value for disabling potential futur autowiring of other class, then i'm 👍 for |
but what if we add something else in the future that autowires? Then this configuration property becomes too generic and we're screwed. |
I really like |
And even if we want to split we can do somehting like that in the futur
|
Oke, I will change it. |
Shouldn't we also remove these aliases then? <service id="Http\Message\MessageFactory" alias="httplug.message_factory" public="false" />
<service id="Http\Message\RequestFactory" alias="httplug.message_factory" public="false" />
<service id="Http\Message\ResponseFactory" alias="httplug.message_factory" public="false" />
<service id="Http\Message\StreamFactory" alias="httplug.stream_factory" public="false" />
<service id="Http\Message\UriFactory" alias="httplug.uri_factory" public="false" /> |
96121b4
to
3cfe74b
Compare
Rebased PR and applied changes. |
oh, so we do autowire other things. i feel that it makes no sense to disable autowiring the factories. and therefore i would want to call it |
I'm fine with that :) didn't know either there was autowiring for other classes sorry for the noise. Thanks @ruudk for checking those things |
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.
Thank you
3cfe74b
to
b54efdb
Compare
Updated the PR one more time ;) |
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.
cool! minor nitpick for the changelog, and the lowest version tests break. i suggest skipping your test on php 5 to keep this sane.
b35fcfc
to
083a825
Compare
one last thing i noticed: you add a git submodule |
083a825
to
7fa5109
Compare
Good catch. I accidentally staged that directory after all changing this PR 10 times ;) It's fixed now. |
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.
Thank you.
thanks a lot and sorry for the back and forth! |
i documented this in php-http/documentation#260 |
What's in this PR?
This allows you to disable the registration of the default HTTPlug client.
Why?
We are heavily using Symfony's auto wire functionality. Sometimes, developer inject HttpClient in the constructor without actually specifying the exact
httplug.client.name
. No error is thrown, and HTTPlug just picks thehttplug.client.default
service (or the first client it can find)Checklist