-
Notifications
You must be signed in to change notification settings - Fork 50
Add a discovery strategy #85
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
@@ -0,0 +1,43 @@ | |||
<?php | |||
|
|||
namespace Http\HttplugBundle; |
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.
should we put this in a sub-namespace "Discovery"?
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.
Sure.
this makes sense to me. what happens if we have no client explicitly configured? then the HttplugBundle uses discovery itself - do we have a chicken-and-egg problem here? this is not complete yet, you need to prepend the discovery strategy so that it actually does something, right? do you want to add a container tag for discovery strategies? not sure how you can make this executed in the generated container, probably need to add a call to the definition of the discovery service itself? |
I believe that is fine as long as we fetch the HttpClient before we add the new strategy. Otherwise we will get problems with the discovery cache.
Correct.
Im not sure that will work. The problem is that there is not discovery service. It is a class with static properties that will forget their configuration at each request. We cant really use the dependency injection as you normally would. (As far as I know). Feel free to make changes and try an idea if you got any. But remember to test the code with a prebuilt container as well. |
This is ready for review and merge. A question that I want you to consider: Are we okey with the new strategy being injected on request and commands like this? |
i think this makes sense, yes. thanks tobias! do we need to document this somewhere? like saying in the bundle doc that the configured client will also be found by discovery? |
I would say that would be pretty standard feature. I as a user do not care if it the client is auto-discovered or not.. What we should mention in the docs though is now we can log all HTTP messages sent by your application. The end developer does not need do to anything special but making sure their third-party libraries support HTTPlug. ".... So if you want a nice web debug toolbar integration for all request .... please send PRs to third party lib to use HTTPlug". |
Thank you for merging BTW! |
To be honest, I am not sure about this: what if I have two separate client configured with separate authentication details, plugins, etc. What happens then if I call discovery somewhere in the middle of the code? Will it return one of the configured clients? |
as i understood, it will use the "default" client. and i think the doc should mention this. its not that obvious to me - auto discovery is not a feature of the HttplugBundle, so being explicit about it could avoid confusion. (but mention to prefer explicit injection if possible) |
okay, but let's say the default client in a micro-application is configured to use authentication and there is a base URL too. If I use the discovery in any library, I will get this client instead of a "pure" unconfigured one and that could cause problems. I would say people should use the bundle and the container to get a client and then it will be visible in the profiler. This way any other code (external library, etc) which uses the discovery could receive a non-functional client and could lead to a case which is quite hard to debug. |
Can we make this configurable? Discovery itself is already magic, and I am a little bit uncomfortable with too much magic. Personally I don't miss a non-configured client from the profiler, if any third party code uses the discovery. That's rather wrong configuration. But if this is always turned on then the scenario outlined above could cause many headaches. |
You are correct @sagikazarmark. I did not think of that. This new Discovery is using the "default" client, ie the first configured client. That is not the same client as you would get if you use the CommonClassesStrategy. The purpose of this PR is to enable the debug toolbar for auto discovered clients. It is not the purpose to configure clients for auto discovery. |
But this is what actually happens, isn't it? It registers the default client (discovered or manually configured) in the discovery. |
could we emulate normal discovery and then wrap the debug client around it? or otherwise have a configuration option to explicitly activate the feature, at which point the user is aware what client they are using. we could then even allow to specify which client to use... |
Yes, I'll make sure to update |
I think we can handle this in the strategy internally: when discovery starts set a static flag to true then call the discovery again. If the flag is already true, do not return candidates and allow the discovery to resolve a candidate, then wrap the client, clear the cache (?) and set the flag to false. Dunno if this could work. |
Adds a new discovery strategy to have discovery find the configured client.
So what about this one? I would love to tag a new release after #84, but this one is a blocker IMO. |
See https://github.com/php-http/HttplugBundle/tree/dev-conf-discovery Im currently working on it. |
Adds a new discovery strategy to have discovery find the configured client.
The clients found by discovery is not logged by the dev toolbar. This PR will add a new strategy that make sure we find a configured client.
Problems
We need to make sure constructor of
ConfiguredClientsStrategy
is executed. Because everything in the dependency injection is cached we can rely on that.A hack that will work is to register
httplug.strategy
as a event listener onkernel.request
andconsole.command
... Not sure if Im happy with that. Any input is welcome.This PR is blocked by
Bugfixes discovery#71Allow for a candidate to have a Closure as a class parameter discovery#66