Skip to content

Commit ec31be1

Browse files
Switch to PSR18 client impl
1 parent b3a7252 commit ec31be1

20 files changed

+125
-114
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ matrix:
2121
- php: 7.2
2222
name: Backward compatibillity check
2323
env: DEPENDENCIES="roave/backward-compatibility-check" TEST_COMMAND="./.github/bc-test.sh"
24-
- php: 7.1
24+
- php: 7.4
2525
name: phpstan
2626
script:
2727
- vendor/bin/phpstan analyse --no-progress

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,34 @@ Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4]
2020
## Requirements
2121

2222
* PHP >= 7.1
23-
* A [HTTP client](https://packagist.org/providers/php-http/client-implementation)
23+
* A [HTTP client](https://packagist.org/providers/psr/http-client-implementation)
2424
* A [PSR-7 implementation](https://packagist.org/providers/psr/http-message-implementation)
2525
* (optional) PHPUnit to run tests.
2626

2727
## Install
2828

29-
Via Composer:
29+
Via [Composer](https://getcomposer.org).
30+
31+
### PHP 7.2+:
3032

3133
```bash
32-
$ composer require knplabs/github-api php-http/guzzle6-adapter "^1.1"
34+
composer require knplabs/github-api guzzlehttp/guzzle:^7.0.1
3335
```
3436

35-
Why `php-http/guzzle6-adapter`? We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io/). Read about clients in our [docs](doc/customize.md).
37+
### PHP 7.1+:
38+
39+
```bash
40+
composer require knplabs/github-api php-http/guzzle6-adapter:^2.0.1
41+
```
3642

43+
### Laravel 5.5+:
44+
45+
```bash
46+
composer require graham-campbell/github guzzlehttp/guzzle:^7.0.1
47+
```
3748

38-
## Using Laravel?
49+
We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io). Read about clients in our [docs](doc/customize.md). [graham-campbell/github](https://github.com/GrahamCampbell/Laravel-GitHub) is by [Graham Campbell](https://github.com/GrahamCampbell).
3950

40-
[Laravel GitHub](https://github.com/GrahamCampbell/Laravel-GitHub) by [Graham Campbell](https://github.com/GrahamCampbell) might interest you.
4151

4252
## Basic usage of `php-github-api` client
4353

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
],
1919
"require": {
2020
"php": "^7.1",
21-
"psr/http-message": "^1.0",
21+
"php-http/client-common": "^2.1",
22+
"php-http/cache-plugin": "^1.7",
23+
"php-http/discovery": "^1.7",
24+
"php-http/httplug": "^2.1",
2225
"psr/cache": "^1.0",
23-
"php-http/httplug": "^1.1 || ^2.0",
24-
"php-http/discovery": "^1.0",
25-
"php-http/client-implementation": "^1.0",
26-
"php-http/client-common": "^1.6 || ^2.0",
27-
"php-http/cache-plugin": "^1.4"
26+
"psr/http-client-implementation": "^1.0",
27+
"psr/http-message": "^1.0"
2828
},
2929
"require-dev": {
3030
"phpunit/phpunit": "^7.0 || ^8.0",
31-
"php-http/guzzle6-adapter": "^1.0 || ^2.0",
31+
"php-http/guzzle6-adapter": "^2.0",
3232
"php-http/mock-client": "^1.2",
3333
"guzzlehttp/psr7": "^1.2",
3434
"cache/array-adapter": "^0.4",

lib/Github/Api/AbstractApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ protected function delete($path, array $parameters = [], array $requestHeaders =
232232
*
233233
* @param array $parameters Request parameters
234234
*
235-
* @return null|string
235+
* @return string|null
236236
*/
237237
protected function createJsonBody(array $parameters)
238238
{

lib/Github/Api/Repo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function showById($id)
183183
* @param string $description repository description
184184
* @param string $homepage homepage url
185185
* @param bool $public `true` for public, `false` for private
186-
* @param null|string $organization username of organization if applicable
186+
* @param string|null $organization username of organization if applicable
187187
* @param bool $hasIssues `true` to enable issues for this repository, `false` to disable them
188188
* @param bool $hasWiki `true` to enable the wiki for this repository, `false` to disable it
189189
* @param bool $hasDownloads `true` to enable downloads for this repository, `false` to disable them

lib/Github/Api/Repository/Contents.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function configure($bodyType = null)
4545
*
4646
* @param string $username the user who owns the repository
4747
* @param string $repository the name of the repository
48-
* @param null|string $reference reference to a branch or commit
48+
* @param string|null $reference reference to a branch or commit
4949
*
5050
* @return array information for README file
5151
*/
@@ -63,8 +63,8 @@ public function readme($username, $repository, $reference = null)
6363
*
6464
* @param string $username the user who owns the repository
6565
* @param string $repository the name of the repository
66-
* @param null|string $path path to file or directory
67-
* @param null|string $reference reference to a branch or commit
66+
* @param string|null $path path to file or directory
67+
* @param string|null $reference reference to a branch or commit
6868
*
6969
* @return array|string information for file | information for each item in directory
7070
*/
@@ -90,7 +90,7 @@ public function show($username, $repository, $path = null, $reference = null)
9090
* @param string $path path to file
9191
* @param string $content contents of the new file
9292
* @param string $message the commit message
93-
* @param null|string $branch name of a branch
93+
* @param string|null $branch name of a branch
9494
* @param null|array $committer information about the committer
9595
*
9696
* @throws MissingArgumentException
@@ -126,7 +126,7 @@ public function create($username, $repository, $path, $content, $message, $branc
126126
* @param string $username the user who owns the repository
127127
* @param string $repository the name of the repository
128128
* @param string $path path of file to check
129-
* @param null|string $reference reference to a branch or commit
129+
* @param string|null $reference reference to a branch or commit
130130
*
131131
* @return bool
132132
*/
@@ -166,7 +166,7 @@ public function exists($username, $repository, $path, $reference = null)
166166
* @param string $content contents of the new file
167167
* @param string $message the commit message
168168
* @param string $sha blob SHA of the file being replaced
169-
* @param null|string $branch name of a branch
169+
* @param string|null $branch name of a branch
170170
* @param null|array $committer information about the committer
171171
*
172172
* @throws MissingArgumentException
@@ -207,7 +207,7 @@ public function update($username, $repository, $path, $content, $message, $sha,
207207
* @param string $path path to file
208208
* @param string $message the commit message
209209
* @param string $sha blob SHA of the file being deleted
210-
* @param null|string $branch name of a branch
210+
* @param string|null $branch name of a branch
211211
* @param null|array $committer information about the committer
212212
*
213213
* @throws MissingArgumentException
@@ -245,7 +245,7 @@ public function rm($username, $repository, $path, $message, $sha, $branch = null
245245
* @param string $username the user who owns the repository
246246
* @param string $repository the name of the repository
247247
* @param string $format format of archive: tarball or zipball
248-
* @param null|string $reference reference to a branch or commit
248+
* @param string|null $reference reference to a branch or commit
249249
*
250250
* @return string repository archive binary data
251251
*/
@@ -265,12 +265,12 @@ public function archive($username, $repository, $format, $reference = null)
265265
* @param string $username the user who owns the repository
266266
* @param string $repository the name of the repository
267267
* @param string $path path to file
268-
* @param null|string $reference reference to a branch or commit
268+
* @param string|null $reference reference to a branch or commit
269269
*
270270
* @throws InvalidArgumentException If $path is not a file or if its encoding is different from base64
271271
* @throws ErrorException If $path doesn't include a 'content' index
272272
*
273-
* @return null|string content of file, or null in case of base64_decode failure
273+
* @return string|null content of file, or null in case of base64_decode failure
274274
*/
275275
public function download($username, $repository, $path, $reference = null)
276276
{

lib/Github/Client.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
use Github\HttpClient\Plugin\PathPrepend;
1313
use Http\Client\Common\HttpMethodsClient;
1414
use Http\Client\Common\Plugin;
15-
use Http\Client\HttpClient;
1615
use Http\Discovery\UriFactoryDiscovery;
1716
use Psr\Cache\CacheItemPoolInterface;
17+
use Psr\Http\Client\ClientInterface;
1818

1919
/**
2020
* Simple yet very cool PHP GitHub client.
@@ -161,13 +161,13 @@ public function __construct(Builder $httpClientBuilder = null, $apiVersion = nul
161161
}
162162

163163
/**
164-
* Create a Github\Client using a HttpClient.
164+
* Create a Github\Client using a HTTP client.
165165
*
166-
* @param HttpClient $httpClient
166+
* @param ClientInterface $httpClient
167167
*
168168
* @return Client
169169
*/
170-
public static function createWithHttpClient(HttpClient $httpClient)
170+
public static function createWithHttpClient(ClientInterface $httpClient)
171171
{
172172
$builder = new Builder($httpClient);
173173

@@ -329,8 +329,8 @@ public function api($name)
329329
* Authenticate a user for all next requests.
330330
*
331331
* @param string $tokenOrLogin GitHub private token/username/client ID
332-
* @param null|string $password GitHub password/secret (optionally can contain $authMethod)
333-
* @param null|string $authMethod One of the AUTH_* class constants
332+
* @param string|null $password GitHub password/secret (optionally can contain $authMethod)
333+
* @param string|null $authMethod One of the AUTH_* class constants
334334
*
335335
* @throws InvalidArgumentException If no authentication method was given
336336
*/

lib/Github/HttpClient/Builder.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
use Http\Client\Common\Plugin;
77
use Http\Client\Common\Plugin\Cache\Generator\HeaderCacheKeyGenerator;
88
use Http\Client\Common\PluginClientFactory;
9-
use Http\Client\HttpClient;
10-
use Http\Discovery\HttpClientDiscovery;
119
use Http\Discovery\MessageFactoryDiscovery;
10+
use Http\Discovery\Psr18ClientDiscovery;
1211
use Http\Discovery\StreamFactoryDiscovery;
1312
use Http\Message\RequestFactory;
1413
use Http\Message\StreamFactory;
1514
use Psr\Cache\CacheItemPoolInterface;
15+
use Psr\Http\Client\ClientInterface;
1616

1717
/**
1818
* A builder that builds the API client.
@@ -25,7 +25,7 @@ class Builder
2525
/**
2626
* The object that sends HTTP messages.
2727
*
28-
* @var HttpClient
28+
* @var ClientInterface
2929
*/
3030
private $httpClient;
3131

@@ -73,16 +73,16 @@ class Builder
7373
private $headers = [];
7474

7575
/**
76-
* @param HttpClient $httpClient
77-
* @param RequestFactory $requestFactory
78-
* @param StreamFactory $streamFactory
76+
* @param ClientInterface $httpClient
77+
* @param RequestFactory $requestFactory
78+
* @param StreamFactory $streamFactory
7979
*/
8080
public function __construct(
81-
HttpClient $httpClient = null,
81+
ClientInterface $httpClient = null,
8282
RequestFactory $requestFactory = null,
8383
StreamFactory $streamFactory = null
8484
) {
85-
$this->httpClient = $httpClient ?: HttpClientDiscovery::find();
85+
$this->httpClient = $httpClient ?: Psr18ClientDiscovery::find();
8686
$this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find();
8787
$this->streamFactory = $streamFactory ?: StreamFactoryDiscovery::find();
8888
}

lib/Github/HttpClient/Message/ResponseMediator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static function getPagination(ResponseInterface $response)
5252
/**
5353
* @param ResponseInterface $response
5454
*
55-
* @return null|string
55+
* @return string|null
5656
*/
5757
public static function getApiLimit(ResponseInterface $response)
5858
{

lib/Github/HttpClient/Plugin/Authentication.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Github\Client;
66
use Github\Exception\RuntimeException;
77
use Http\Client\Common\Plugin;
8+
use Http\Promise\Promise;
89
use Psr\Http\Message\RequestInterface;
910

1011
/**
@@ -14,12 +15,26 @@
1415
*/
1516
class Authentication implements Plugin
1617
{
17-
use Plugin\VersionBridgePlugin;
18-
18+
/**
19+
* @var string
20+
*/
1921
private $tokenOrLogin;
22+
23+
/**
24+
* @var string|null
25+
*/
2026
private $password;
27+
28+
/**
29+
* @var string|null
30+
*/
2131
private $method;
2232

33+
/**
34+
* @param string $tokenOrLogin GitHub private token/username/client ID
35+
* @param string|null $password GitHub password/secret (optionally can contain $method)
36+
* @param string|null $method One of the AUTH_* class constants
37+
*/
2338
public function __construct($tokenOrLogin, $password, $method)
2439
{
2540
$this->tokenOrLogin = $tokenOrLogin;
@@ -30,7 +45,7 @@ public function __construct($tokenOrLogin, $password, $method)
3045
/**
3146
* {@inheritdoc}
3247
*/
33-
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
48+
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
3449
{
3550
switch ($this->method) {
3651
case Client::AUTH_HTTP_PASSWORD:

lib/Github/HttpClient/Plugin/GithubExceptionThrower.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Github\Exception\ValidationFailedException;
1010
use Github\HttpClient\Message\ResponseMediator;
1111
use Http\Client\Common\Plugin;
12+
use Http\Promise\Promise;
1213
use Psr\Http\Message\RequestInterface;
1314
use Psr\Http\Message\ResponseInterface;
1415

@@ -18,12 +19,10 @@
1819
*/
1920
class GithubExceptionThrower implements Plugin
2021
{
21-
use Plugin\VersionBridgePlugin;
22-
2322
/**
2423
* {@inheritdoc}
2524
*/
26-
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
25+
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
2726
{
2827
return $next($request)->then(function (ResponseInterface $response) use ($request) {
2928
if ($response->getStatusCode() < 400 || $response->getStatusCode() > 600) {

lib/Github/HttpClient/Plugin/History.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Github\HttpClient\Plugin;
44

55
use Http\Client\Common\Plugin\Journal;
6+
use Psr\Http\Client\ClientExceptionInterface;
67
use Psr\Http\Message\RequestInterface;
78
use Psr\Http\Message\ResponseInterface;
89

@@ -13,10 +14,8 @@
1314
*/
1415
class History implements Journal
1516
{
16-
use HistoryTrait;
17-
1817
/**
19-
* @var ResponseInterface
18+
* @var ResponseInterface|null
2019
*/
2120
private $lastResponse;
2221

@@ -32,4 +31,8 @@ public function addSuccess(RequestInterface $request, ResponseInterface $respons
3231
{
3332
$this->lastResponse = $response;
3433
}
34+
35+
public function addFailure(RequestInterface $request, ClientExceptionInterface $exception)
36+
{
37+
}
3538
}

lib/Github/HttpClient/Plugin/HistoryTrait.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)