Skip to content

Commit

Permalink
Update package, use Client Tools
Browse files Browse the repository at this point in the history
  • Loading branch information
sagikazarmark committed Nov 19, 2015
1 parent 75ddc71 commit 2103114
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 125 deletions.
32 changes: 26 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:

Expand All @@ -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
Expand All @@ -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.
1 change: 1 addition & 0 deletions LICENSE
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
Expand Down
12 changes: 4 additions & 8 deletions README.md
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)
Expand Down Expand Up @@ -27,7 +27,7 @@ Please see the [official documentation](http://php-http.readthedocs.org/en/lates
## Testing

``` bash
$ phpunit
$ composer test
```


Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Guzzle 6 HTTP Adapter",
"license": "MIT",
"keywords": ["guzzle", "http"],
"homepage": "http://php-http.org",
"homepage": "http://httplug.io",
"authors": [
{
"name": "David de Boer",
Expand All @@ -17,6 +17,7 @@
"require": {
"php": ">=5.5.0",
"php-http/httplug": "^1.0@dev",
"php-http/client-tools": "^0.1@dev",
"guzzlehttp/guzzle": "^6.0"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="Guzzle 6 Adapter Test Suite">
<testsuite name="Guzzle 6 HTTP Adapter Test Suite">
<directory>tests/</directory>
</testsuite>
</testsuites>
Expand Down
34 changes: 9 additions & 25 deletions src/Guzzle6HttpAdapter.php
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);
}
}
12 changes: 10 additions & 2 deletions src/Guzzle6Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -148,4 +157,3 @@ private function handleException(GuzzleExceptions\GuzzleException $exception, Re
return new HttplugException\TransferException($exception->getMessage(), 0, $exception);
}
}

9 changes: 0 additions & 9 deletions tests/Guzzle6CurlHttpAdapterTest.php
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;
Expand Down
9 changes: 0 additions & 9 deletions tests/Guzzle6CurlHttpAsyncAdapterTest.php
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;
Expand Down
9 changes: 0 additions & 9 deletions tests/Guzzle6HttpAdapterTest.php
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;
Expand Down
9 changes: 0 additions & 9 deletions tests/Guzzle6HttpAsyncAdapterTest.php
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;
Expand Down
9 changes: 0 additions & 9 deletions tests/Guzzle6MultiCurlHttpAdapterTest.php
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;
Expand Down
9 changes: 0 additions & 9 deletions tests/Guzzle6MultiCurlHttpAsyncAdapterTest.php
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;
Expand Down
11 changes: 1 addition & 10 deletions tests/Guzzle6PromiseExceptionTest.php
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;
Expand Down Expand Up @@ -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");
}
}
}
9 changes: 0 additions & 9 deletions tests/Guzzle6StreamHttpAdapterTest.php
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;
Expand Down
9 changes: 0 additions & 9 deletions tests/Guzzle6StreamHttpAsyncAdapterTest.php
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;
Expand Down

0 comments on commit 2103114

Please sign in to comment.