-
Notifications
You must be signed in to change notification settings - Fork 50
Make sure we support any psr-18 client #295
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
Nyholm
commented
Dec 29, 2018
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Related tickets | fixes #276 |
Documentation | |
License | MIT |
This is just minor improvements. It works even without this patch |
@@ -6,6 +6,7 @@ | |||
use Http\Client\HttpAsyncClient; | |||
use Http\Client\HttpClient; | |||
use Http\HttplugBundle\ClientFactory\ClientFactory; | |||
use Psr\Http\Client\ClientInterface; |
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 have checked out at your branch. I run composer update
but still this namespace is not discovered by PHPStorm.. and the package is not installed.
Could it be that exists localy on you because you have not run composer update
?
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.
You need to make sure you install php-http/client-common:2.0-dev. If not you will get httplug: 1.1
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.
Oh, you are correct.
Oh, you are correct. Since we have a bunch if httplug1.0 clients in require-dev we will never be able to install httplug2.0 by just running composer update. I tested this by
I created my client like: namespace App\Service;
use Nyholm\Psr7\Response;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
class MyHttpClient implements ClientInterface
{
public function sendRequest(RequestInterface $request): ResponseInterface
{
return new Response(250);
}
} And I registered it like: httplug:
main_alias:
client: httplug.client.my_client
discovery:
client: 'auto'
clients:
my_client:
service: 'App\Service\MyHttpClient'
http_methods_client: true
plugins:
- 'httplug.plugin.content_length'
- 'httplug.plugin.redirect'
|
Well.. on the current a PR you want to do this Secondly as a developer of this package... yes I do not depend on PSR client and I might not want to depend... As a consumer using this package.. is there a way that I feel confident that the client I am retrieving is a PSR one? Haven't discovered all the full aspects of the bundle so on this point I might be wrong... I think there is some autodiscovery mechanism.. that's what I am talking about. Thirdly... here wont this miss the exceptions? |
@Nyholm I think that your example works out of luck.. although I know that this was by design it just happens that PSR client and PHP-HTTP to have the same signature for instance the |
Yes, I agree. But it works =)
The auto discovery is here: https://github.com/php-http/discovery And no, you cannot be sure unless you decide what you want. If you do
That should be updated. Thank you!
Technically, yes. But we have code that make sure you submit a client. Check out the ProfileClient and the FlexibleClient |
OK.. I missed the I will have a deeper look because then I don't quite fully get it how your code example posted above worked with master :/
|
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.
not sure i understand the discussion on the PR. to me this looks correct. we allow either interface, and PHP will not explode if it does not know about a namespace, e.g. the PSR interfaces, in the case of running with httplug 1.x.
is this issue fixed with #294? can you rebase and maybe add some tests that make sure both httplug 1 (when installed) and a psr-18 client (when installed) work with this code? |
Correct. |
Yea.. I understand that I did not express my self correct on this.. also I was lost too because I thought that PHP will explode if it does not find a namespace which it doesn't... tests will be helpful to.. |
no worries, better speak up than silently be confused ;-) and i think it was very helpful here, because in the beginning we had no test covering the changes, which is dangerous. and the fact that php ignores unknown namespaces in |
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.
looks good to merge to me.
lets give @gmponos time to review as well.
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.
According to the scope of the changes they are fine.. on an unrelated topic I believe that bundle must drop support for PHP 5 and HttpClient interface and bump to a new version.
Why do you believe that? |
Continue in #296 |