Skip to content
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

Merged
merged 8 commits into from Mar 25, 2016
Merged

Using Httplug instead of Guzzle6 #505

merged 8 commits into from Mar 25, 2016

Conversation

Nyholm
Copy link
Contributor

@Nyholm Nyholm commented Mar 21, 2016

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 function HttpClientFactory::createGuzzle and also the config parameter named guzzle.client.

This will fix #491

Usage

/** @var Payum $payum */
$payum = (new PayumBuilder())
    ->addDefaultStorages()
    ->addGateway('gatewayName', [
        'factory' => 'aGateway'
        'httplug.client' => new \Http\Adapter\Guzzle6\Client(),
    ])
    ->getPayum()
;

TODO

  • Make code changes
  • Deprecate existing classes tightly coupled to Guzzle
  • Add documentation

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.

* @return HttpClientInterface
*/
public static function create()
{
return new HttpClient(static::createGuzzle());
return new HttpClient(HttpClientDiscovery::find());
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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

@Nyholm
Copy link
Contributor Author

Nyholm commented Mar 21, 2016

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) {
Copy link
Member

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@Nyholm
Copy link
Contributor Author

Nyholm commented Mar 22, 2016

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();;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey, will do.

@makasim
Copy link
Member

makasim commented Mar 22, 2016

Does it look good? Should I start writing some docs?

Pretty good I must say. There is one comment about the injection of message factory only.

@Nyholm
Copy link
Contributor Author

Nyholm commented Mar 22, 2016

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",
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@Nyholm Nyholm changed the title [WIP] Using Httplug instead of Guzzle6 Using Httplug instead of Guzzle6 Mar 23, 2016
@Nyholm
Copy link
Contributor Author

Nyholm commented Mar 23, 2016

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());
Copy link
Member

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)) {
Copy link
Member

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"

@Nyholm
Copy link
Contributor Author

Nyholm commented Mar 25, 2016

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 )
Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeap

@Nyholm
Copy link
Contributor Author

Nyholm commented Mar 25, 2016

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).

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@makasim makasim merged commit fa3a9b1 into Payum:master Mar 25, 2016
@makasim
Copy link
Member

makasim commented Mar 25, 2016

@Nyholm Thanks for your work!

@makasim
Copy link
Member

makasim commented Mar 25, 2016

That's a great move forward.

@Nyholm
Copy link
Contributor Author

Nyholm commented Mar 25, 2016

Thank you for the feedback and for merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace Guzzle6 with HTTPlug
2 participants