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
Using Httplug instead of Guzzle6 #505
Conversation
* @return HttpClientInterface | ||
*/ | ||
public static function create() | ||
{ | ||
return new HttpClient(static::createGuzzle()); | ||
return new HttpClient(HttpClientDiscovery::find()); |
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.
it throws an exception if there is not any implementations (packages), am I right?
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.
Yes. If you try to use discovery without installing puli or if you do not have a psr7 implementation, this will throw an exception.
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.
So we can drop a guzzle as default client, since users are forced to take care of this on composer update. I am positive to it as long as the exception message is clear and a user understands how to proceed
Thank you for reviewing this so quickly. |
@@ -111,7 +116,7 @@ public function createConfig(array $config = array()) | |||
protected function buildClosures(ArrayObject $config) | |||
{ | |||
// with higher priority | |||
foreach (['guzzle.client', 'payum.http_client', 'payum.paths', 'twig.env'] as $name) { | |||
foreach (['payum.http_client', 'payum.paths', 'twig.env'] as $name) { |
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.
@Nyholm I think you have to add a httplug_client
options here too (before the http_client one).
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.
I've updated the PR according to your suggestions. We are now completely independent from Guzzle. Does it look good? Should I start writing some docs? |
@@ -138,6 +144,7 @@ public function __construct(array $options, HttpClientInterface $client = null) | |||
|
|||
$this->options = $options; | |||
$this->client = $client ?: HttpClientFactory::create(); | |||
$this->messageFactory = $options['httplug.message_factory'] ?: MessageFactoryDiscovery::find();; |
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'd prefer to have it injected as third argument (optional) and if not passed use a discovery logic. FYI I am going to make this argument not optional in 2.x version as they managed by gateway factory.
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.
Okey, will do.
Pretty good I must say. There is one comment about the injection of message factory only. |
I made the changes you suggested. Also, I added a HttplugClient and let the old HttpClient be. That means we do not break BC at all. |
@@ -39,7 +39,10 @@ | |||
"require": { | |||
"php": "^5.5.0|^7.0", | |||
"payum/iso4217": "~1.0", | |||
"guzzlehttp/guzzle": "~6.0", | |||
"php-http/httplug": "^1.0", |
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.
any reason to require it explicitly. I personally dont think we need it since we have a php-http/client-implementation
here. Do I miss something?
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 are correct. This package is required indirectly. This row will not have any effect in practice.
The reason I added it is because I believe it is good practice to specify all your dependencie and not rely on other packages to pull in the dependencies. We are using classes/interfaces from this package and that is why I've specified it as a dependency.
I've noticed that this is very opinionated topic and I'm fine with removing it if you like.
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.
let's keep it as is.
Ive updated the docs, squashed my commits and also updated the PR description. |
[httplug] guess client and message factory.
@@ -28,6 +46,6 @@ public static function createGuzzle() | |||
*/ | |||
public static function create() | |||
{ | |||
return new HttpClient(static::createGuzzle()); | |||
return new HttplugClient(HttpClientDiscovery::find()); |
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.
this change should be reverted. The whole factory is not used anywhere right now.
|
||
// TODO add "if else" for other message factories provided by httplug. | ||
|
||
if (class_exists(MessageFactoryDiscovery::class)) { |
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.
It would be good to try discovery first and only after fallback to "my solution"
There you go, I've added more Httplug clients. |
* | ||
* @throws \Payum\Core\Exception\InvalidArgumentException if an option is invalid | ||
*/ | ||
public function __construct(array $options, HttpClientInterface $client = null) | ||
public function __construct(array $options, HttpClientInterface $client, MessageFactory $messageFactory ) |
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.
Before I rewrite the failing tests. Is this the function signature that yo want?
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.
yeap
There. Everything we discussed is updated |
## 1.3.0 | ||
|
||
* [http-client] guzzlehttp/guzzle was decoupled and replaced by [Httplug](http://docs.php-http.org/en/latest/httplug/introduction.html). This gives you option to use Guzzle6, Guzzle5, Buzz or any other library to send HTTP messages. Make sure to specify `httplug.client` and `httplug.message_factory` or use [Httplug discovery](http://docs.php-http.org/en/latest/discovery.html). | ||
|
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.
The text is not accurate for current state. I'd like this one:
* [http-client] When you update to Payum 1.3.0 the installation will fail because you need to install a client implementation. If you choose php-http/guzzle6-adapter everything will work exactly as before.
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.
Updated
@Nyholm Thanks for your work! |
That's a great move forward. |
Thank you for the feedback and for merging! |
This is PR will remove our hard coupled dependency on Guzzle6 and instead rely on an interface. This will make the Payum package more SOLID. With this PR we allow users that are stuck with using Guzzle5 to use Payum.
This PR introduce some small BC breaks. I've removed the functionHttpClientFactory::createGuzzle
and also the config parameter namedguzzle.client
.This will fix #491
Usage
TODO
Implications
When you update to Payum 1.3.0 the installation will fail because you need to install a client implementation. If you choose
php-http/guzzle6-adapter
everything will work exactly as before. No BC breaks.