forked from php-http/guzzle6-adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75ddc71
commit 2103114
Showing
16 changed files
with
54 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,9 @@ please be as precise as possible. Here is a little list of required information: | |
|
||
## Security issues | ||
|
||
If you discover any security related issues, please contact us at [[email protected]](mailto:[email protected]) instead of submitting an issue on Github. This allows us to fix the issue and release a security hotfix without publicly disclosing the vulnerability. | ||
If you discover any security related issues, | ||
please contact us at the [security email address](../../#security) instead of submitting an issue on Github. | ||
This allows us to fix the issue and release a security hotfix without publicly disclosing the vulnerability. | ||
|
||
|
||
## Feature requests | ||
|
@@ -28,7 +30,8 @@ easily understood/implement it. | |
|
||
## Sending a Pull Request | ||
|
||
If you're here, you are going to fix a bug or implement a feature and you're the best! To do it, first fork the repository, clone it and create a new branch with the following commands: | ||
If you're here, you are going to fix a bug or implement a feature and you're the best! | ||
To do it, first fork the repository, clone it and create a new branch with the following commands: | ||
|
||
``` bash | ||
$ git clone [email protected]:your-name/repo-name.git | ||
|
@@ -41,7 +44,12 @@ Then install the dependencies through [Composer](https://getcomposer.org/): | |
$ composer install | ||
``` | ||
|
||
Write code and tests. When you are ready, find the testing command in the [README](README.md) and execute it. (This is usually [PHPUnit](http://phpunit.de/) or [PHPSpec](http://phpspec.net/)) | ||
Write code and tests. When you are ready, run the tests. | ||
(This is usually [PHPUnit](http://phpunit.de/) or [PHPSpec](http://phpspec.net/)) | ||
|
||
``` bash | ||
$ composer test | ||
``` | ||
|
||
When you are ready with the code, tested it and documented it, you can commit and push it with the following commands: | ||
|
||
|
@@ -50,11 +58,15 @@ $ git commit -m "Feature or bug fix description" | |
$ git push origin feature-or-bug-fix-description | ||
``` | ||
|
||
**Note:** Please write your commit messages in the imperative and follow the [guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) for clear and concise messages. | ||
**Note:** Please write your commit messages in the imperative and follow the | ||
[guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) for clear and concise messages. | ||
|
||
Then [create a pull request](https://help.github.com/articles/creating-a-pull-request/) on GitHub. | ||
|
||
Please make sure that each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting with the following commands (here, we assume you would like to squash 3 commits in a single one): | ||
Please make sure that each individual commit in your pull request is meaningful. | ||
If you had to make multiple intermediate commits while developing, | ||
please squash them before submitting with the following commands | ||
(here, we assume you would like to squash 3 commits in a single one): | ||
|
||
``` bash | ||
$ git rebase -i HEAD~3 | ||
|
@@ -77,4 +89,12 @@ you must follow these rules. | |
|
||
## Semver | ||
|
||
We are trying to follow [semver](http://semver.org/). When you are making BC breaking changes, please let us know why you think it is important. In this case, your patch can only be included in the next major version. | ||
We are trying to follow [semver](http://semver.org/). When you are making BC breaking changes, | ||
please let us know why you think it is important. | ||
In this case, your patch can only be included in the next major version. | ||
|
||
|
||
## Code of Conduct | ||
|
||
This project is released with a [Contributor Code of Conduct](CONDUCT.md). | ||
By participating in this project you agree to abide by its terms. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Copyright (c) 2014-2015 Eric GELOEN <[email protected]> | ||
Copyright (c) 2015 PHP HTTP Team <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Guzzle 6 Adapter | ||
# Guzzle 6 HTTP Adapter | ||
|
||
[![Latest Version](https://img.shields.io/github/release/php-http/guzzle6-adapter.svg?style=flat-square)](https://github.com/php-http/guzzle6-adapter/releases) | ||
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) | ||
|
@@ -27,7 +27,7 @@ Please see the [official documentation](http://php-http.readthedocs.org/en/lates | |
## Testing | ||
|
||
``` bash | ||
$ phpunit | ||
$ composer test | ||
``` | ||
|
||
|
||
|
@@ -38,12 +38,8 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details | |
|
||
## Security | ||
|
||
If you discover any security related issues, please contact us at [[email protected]](mailto:[email protected]). | ||
|
||
|
||
## Credits | ||
|
||
Thanks to [David de Boer](https://github.com/ddeboer) for implementing this adapter. | ||
If you discover any security related issues, please contact us at [[email protected]](mailto:[email protected]) | ||
or [[email protected]](mailto:[email protected]). | ||
|
||
|
||
## License | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,44 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Http Adapter package. | ||
* | ||
* (c) Eric GELOEN <[email protected]> | ||
* | ||
* For the full copyright and license information, please read the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Http\Adapter; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\ClientInterface; | ||
use Http\Client\HttpAsyncClient; | ||
use Http\Client\HttpClient; | ||
use Http\Client\Promise; | ||
use Http\Client\Tools\HttpClientEmulator; | ||
use Psr\Http\Message\RequestInterface; | ||
|
||
/** | ||
* HTTP Adapter for Guzzle 6. | ||
* | ||
* @author David de Boer <[email protected]> | ||
*/ | ||
class Guzzle6HttpAdapter implements HttpClient, HttpAsyncClient | ||
{ | ||
use HttpClientEmulator; | ||
|
||
/** | ||
* @var ClientInterface | ||
*/ | ||
private $client; | ||
|
||
/** | ||
* @param ClientInterface|null $client Guzzle client | ||
* @param ClientInterface|null $client | ||
*/ | ||
public function __construct(ClientInterface $client = null) | ||
{ | ||
$this->client = $client ?: new Client(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function sendRequest(RequestInterface $request) | ||
{ | ||
$promise = $this->sendAsyncRequest($request); | ||
$promise->wait(); | ||
|
||
if ($promise->getState() == Promise::REJECTED) { | ||
throw $promise->getException(); | ||
} | ||
|
||
return $promise->getResponse(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function sendAsyncRequest(RequestInterface $request) | ||
{ | ||
return new Guzzle6Promise($this->client->sendAsync($request), $request); | ||
$promise = $this->client->sendAsync($request); | ||
|
||
return new Guzzle6Promise($promise, $request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,15 @@ | |
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
* Wrapper around Guzzle promises. | ||
* | ||
* @author Joel Wurtz <[email protected]> | ||
*/ | ||
class Guzzle6Promise implements Promise | ||
{ | ||
/** | ||
* @var \GuzzleHttp\Promise\PromiseInterface | ||
* @var PromiseInterface | ||
*/ | ||
private $promise; | ||
|
||
|
@@ -36,6 +41,10 @@ class Guzzle6Promise implements Promise | |
*/ | ||
private $request; | ||
|
||
/** | ||
* @param PromiseInterface $promise | ||
* @param RequestInterface $request | ||
*/ | ||
public function __construct(PromiseInterface $promise, RequestInterface $request) | ||
{ | ||
$this->request = $request; | ||
|
@@ -148,4 +157,3 @@ private function handleException(GuzzleExceptions\GuzzleException $exception, Re | |
return new HttplugException\TransferException($exception->getMessage(), 0, $exception); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Http Adapter package. | ||
* | ||
* (c) Eric GELOEN <[email protected]> | ||
* | ||
* For the full copyright and license information, please read the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Http\Adapter\Tests; | ||
|
||
use GuzzleHttp\Handler\CurlHandler; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Http Adapter package. | ||
* | ||
* (c) Eric GELOEN <[email protected]> | ||
* | ||
* For the full copyright and license information, please read the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Http\Adapter\Tests; | ||
|
||
use GuzzleHttp\Handler\CurlHandler; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Http Adapter package. | ||
* | ||
* (c) Eric GELOEN <[email protected]> | ||
* | ||
* For the full copyright and license information, please read the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Http\Adapter\Tests; | ||
|
||
use GuzzleHttp\Client; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Http Adapter package. | ||
* | ||
* (c) Eric GELOEN <[email protected]> | ||
* | ||
* For the full copyright and license information, please read the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Http\Adapter\Tests; | ||
|
||
use GuzzleHttp\Client; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Http Adapter package. | ||
* | ||
* (c) Eric GELOEN <[email protected]> | ||
* | ||
* For the full copyright and license information, please read the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Http\Adapter\Tests; | ||
|
||
use GuzzleHttp\Handler\CurlMultiHandler; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Http Adapter package. | ||
* | ||
* (c) Eric GELOEN <[email protected]> | ||
* | ||
* For the full copyright and license information, please read the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Http\Adapter\Tests; | ||
|
||
use GuzzleHttp\Handler\CurlMultiHandler; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Http Adapter package. | ||
* | ||
* (c) Eric GELOEN <[email protected]> | ||
* | ||
* For the full copyright and license information, please read the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Http\Adapter\Tests; | ||
|
||
use GuzzleHttp\Exception as GuzzleExceptions; | ||
|
@@ -65,4 +56,4 @@ public function testGetException() | |
$outputException = $method->invoke($adapter, new GuzzleExceptions\ServerException('foo', $request), $request); | ||
$this->assertInstanceOf('Http\Client\Exception\RequestException', $outputException, "Guzzle's ServerException with no response should be converted to a RequestException"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Http Adapter package. | ||
* | ||
* (c) Eric GELOEN <[email protected]> | ||
* | ||
* For the full copyright and license information, please read the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Http\Adapter\Tests; | ||
|
||
use GuzzleHttp\Handler\StreamHandler; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Http Adapter package. | ||
* | ||
* (c) Eric GELOEN <[email protected]> | ||
* | ||
* For the full copyright and license information, please read the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Http\Adapter\Tests; | ||
|
||
use GuzzleHttp\Handler\StreamHandler; | ||
|