Skip to content

Commit 4619ebd

Browse files
feature #888 Switch to PSR-17 and remove deprecated code (GrahamCampbell)
This PR was squashed before being merged into the 3.0.x-dev branch. Discussion ---------- This PR removes all the deprecated code from the codebase, and switches to PSR-17 which replaces the old PHP HTTP interfaces, just like PSR-18 replaced some of the others (implemented in an earlier PR). Commits ------- ee1bf7f Removed deprecated code 692ca2a Finished removing old code 1e30efd Update doc/security.md 2054e20 PSR-17 and HttpMethodsClientInterface 0fdecef Returns
1 parent ecc7dcc commit 4619ebd

31 files changed

+110
-952
lines changed

README.md

+8-9
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,29 @@ 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/psr/http-client-implementation)
24-
* A [PSR-7 implementation](https://packagist.org/providers/psr/http-message-implementation)
25-
* (optional) PHPUnit to run tests.
23+
* A [PSR-17 implementation](https://packagist.org/providers/psr/http-factory-implementation)
24+
* A [PSR-18 implementation](https://packagist.org/providers/psr/http-client-implementation)
2625

2726
## Install
2827

2928
Via [Composer](https://getcomposer.org).
3029

31-
### PHP 7.2+:
30+
### PHP 7.1+:
3231

3332
```bash
34-
composer require knplabs/github-api guzzlehttp/guzzle:^7.0.1
33+
composer require knplabs/github-api:^3.0 php-http/guzzle6-adapter:^2.0.1 http-interop/http-factory-guzzle:^1.0
3534
```
3635

37-
### PHP 7.1+:
36+
### PHP 7.2+:
3837

3938
```bash
40-
composer require knplabs/github-api php-http/guzzle6-adapter:^2.0.1
39+
composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0
4140
```
4241

43-
### Laravel 5.5+:
42+
### Laravel 6+:
4443

4544
```bash
46-
composer require graham-campbell/github guzzlehttp/guzzle:^7.0.1
45+
composer require graham-campbell/github^10.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0
4746
```
4847

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

composer.json

+13-10
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,33 @@
1818
],
1919
"require": {
2020
"php": "^7.1",
21-
"php-http/client-common": "^2.1",
21+
"php-http/client-common": "^2.2",
2222
"php-http/cache-plugin": "^1.7",
23-
"php-http/discovery": "^1.7",
23+
"php-http/discovery": "^1.9",
2424
"php-http/httplug": "^2.1",
25+
"php-http/multipart-stream-builder": "^1.1",
2526
"psr/cache": "^1.0",
2627
"psr/http-client-implementation": "^1.0",
28+
"psr/http-factory-implementation": "^1.0",
2729
"psr/http-message": "^1.0"
2830
},
2931
"require-dev": {
30-
"phpunit/phpunit": "^7.0 || ^8.0",
31-
"php-http/guzzle6-adapter": "^2.0",
32-
"php-http/mock-client": "^1.2",
33-
"guzzlehttp/psr7": "^1.2",
34-
"cache/array-adapter": "^0.4",
35-
"phpstan/phpstan": "^0.12.23"
32+
"cache/array-adapter": "^1.0.1",
33+
"guzzlehttp/psr7": "^1.5.2",
34+
"http-interop/http-factory-guzzle": "^1.0",
35+
"php-http/guzzle6-adapter": "^2.0.1",
36+
"php-http/mock-client": "^1.4",
37+
"phpstan/phpstan": "^0.12.32",
38+
"phpstan/extension-installer": "^1.0.4",
39+
"phpstan/phpstan-deprecation-rules": "^0.12.4",
40+
"phpunit/phpunit": "^7.5.15 || ^8.4 || ^9.0"
3641
},
3742
"autoload": {
3843
"psr-4": { "Github\\": "lib/Github/" }
3944
},
4045
"autoload-dev": {
4146
"psr-4": { "Github\\Tests\\": "test/Github/Tests/"}
4247
},
43-
"minimum-stability": "dev",
44-
"prefer-stable": true,
4548
"extra": {
4649
"branch-alias": {
4750
"dev-2.x": "2.15.x-dev",

doc/rate_limits.md

-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Get rate limit wrappers from [GitHub Rate Limit API](http://developer.github.com
55

66
#### Get All Rate Limits
77

8-
##### new way
98
```php
109
/** @var \Github\Api\RateLimit\RateLimitResource[] $rateLimits */
1110
$rateLimits = $client->api('rate_limit')->getResources();
@@ -61,14 +60,6 @@ array(4) {
6160
}
6261
```
6362

64-
65-
##### deprecated way
66-
67-
```php
68-
/** @var array $rateLimits */
69-
$rateLimits = $client->api('rate_limit')->getRateLimits();
70-
```
71-
7263
#### Get Core Rate Limit
7364

7465
```php

doc/security.md

+8-26
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,29 @@ properties on Repositories and some others. Therefore this step is facultative.
66

77
### Authenticate
88

9-
GitHub provides some different ways of authentication. This API implementation implements three of them which are handled by one function:
9+
GitHub provides some different ways of authentication. This API implementation implements three of them which are
10+
handled by one function:
1011

1112
```php
1213
$client->authenticate($usernameOrToken, $password, $method);
1314
```
1415

1516
`$usernameOrToken` is, of course, the username (or in some cases token/client ID, more details you can find below),
16-
and guess what should contain `$password`. The `$method` can contain one of the five allowed values:
17-
18-
#### Deprecated methods
19-
* `Github\Client::AUTH_URL_TOKEN` use `Github\Client::AUTH_ACCESS_TOKEN` instead.
20-
* `Github\Client::AUTH_URL_CLIENT_ID` use `Github\Client::AUTH_CLIENT_ID` instead.
21-
* `Github\Client::AUTH_HTTP_TOKEN` use `Github\Client::AUTH_ACCESS_TOKEN` instead.
22-
* `Github\Client::AUTH_HTTP_PASSWORD` use `Github\Client::AUTH_ACCESS_TOKEN` instead.
17+
and guess what should contain `$password`. The `$method` can contain one of the three allowed values:
2318

2419
#### Supported methods
2520
* `Github\Client::AUTH_CLIENT_ID` - https://developer.github.com/v3/#oauth2-keysecret
2621
* `Github\Client::AUTH_ACCESS_TOKEN` - https://developer.github.com/v3/#oauth2-token-sent-in-a-header
2722
* `Github\Client::AUTH_JWT` - https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-a-github-app
2823

29-
The required value of `$password` depends on the chosen `$method`. For `Github\Client::AUTH_URL_TOKEN`,
30-
`Github\Client::AUTH_HTTP_TOKEN` and `Github\Client::JWT` methods you should provide the API token in
31-
`$usernameOrToken` variable (`$password` is omitted in this particular case). For the
32-
`Github\Client::AUTH_HTTP_PASSWORD`, you should provide the password of the account. When using `Github\Client::AUTH_URL_CLIENT_ID`
33-
`$usernameOrToken` should contain your client ID, and `$password` should contain client secret.
34-
35-
After executing the `$client->authenticate($usernameOrToken, $secret, $method);` method using correct credentials,
36-
all further requests are done as the given user.
24+
The required value of `$password` depends on the chosen `$method`. For `Github\Client::AUTH_ACCESS_TOKEN` and
25+
`Github\Client::JWT` methods you should provide the API token in `$usernameOrToken` variable (`$password` is omitted in
26+
this particular case).
3727

38-
### About authentication methods
39-
40-
The `Github\Client::AUTH_URL_TOKEN` authentication method sends the API token in URL parameters.
41-
The `Github\Client::AUTH_URL_CLIENT_ID` authentication method sends the client ID and secret in URL parameters.
42-
The `Github\Client::AUTH_HTTP_*` authentication methods send their values to GitHub using HTTP Basic Authentication.
4328
The `Github\Client::AUTH_JWT` authentication method sends the specified JSON Web Token in an Authorization header.
4429

45-
`Github\Client::AUTH_URL_TOKEN` used to be the only available authentication method. To prevent existing applications
46-
from changing their behavior in case of an API upgrade, this method is chosen as the default for this API implementation.
47-
48-
Note however that GitHub describes this method as deprecated. In most case you should use the
49-
`Github\Client::AUTH_HTTP_TOKEN` instead.
30+
After executing the `$client->authenticate($usernameOrToken, $secret, $method);` method using correct credentials, all
31+
further requests are done as the given user.
5032

5133
### Authenticating as an Integration
5234

lib/Github/Api/Authorizations.php

-142
Original file line numberDiff line numberDiff line change
@@ -11,100 +11,6 @@
1111
*/
1212
class Authorizations extends AbstractApi
1313
{
14-
use AcceptHeaderTrait;
15-
16-
private function configurePreviewHeader()
17-
{
18-
$this->acceptHeaderValue = 'application/vnd.github.doctor-strange-preview+json';
19-
}
20-
21-
/**
22-
* List all authorizations.
23-
*
24-
* @return array
25-
*
26-
* @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead.
27-
*/
28-
public function all()
29-
{
30-
return $this->get('/authorizations');
31-
}
32-
33-
/**
34-
* Show a single authorization.
35-
*
36-
* @param string $clientId
37-
*
38-
* @return array
39-
*
40-
* @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead.
41-
*/
42-
public function show($clientId)
43-
{
44-
return $this->get('/authorizations/'.rawurlencode($clientId));
45-
}
46-
47-
/**
48-
* Create an authorization.
49-
*
50-
* @param array $params
51-
* @param string|null $OTPCode
52-
*
53-
* @return array
54-
*
55-
* @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead.
56-
*/
57-
public function create(array $params, $OTPCode = null)
58-
{
59-
$headers = null === $OTPCode ? [] : ['X-GitHub-OTP' => $OTPCode];
60-
61-
return $this->post('/authorizations', $params, $headers);
62-
}
63-
64-
/**
65-
* Update an authorization.
66-
*
67-
* @param string $clientId
68-
* @param array $params
69-
*
70-
* @return array
71-
*
72-
* @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead.
73-
*/
74-
public function update($clientId, array $params)
75-
{
76-
return $this->patch('/authorizations/'.rawurlencode($clientId), $params);
77-
}
78-
79-
/**
80-
* Remove an authorization.
81-
*
82-
* @param string $clientId
83-
*
84-
* @return array
85-
*
86-
* @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead.
87-
*/
88-
public function remove($clientId)
89-
{
90-
return $this->delete('/authorizations/'.rawurlencode($clientId));
91-
}
92-
93-
/**
94-
* Check an authorization.
95-
*
96-
* @param string $clientId
97-
* @param string $token
98-
*
99-
* @return array
100-
*
101-
* @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::checkToken() instead.
102-
*/
103-
public function check($clientId, $token)
104-
{
105-
return $this->get('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token));
106-
}
107-
10814
/**
10915
* Check an application token.
11016
*
@@ -115,26 +21,9 @@ public function check($clientId, $token)
11521
*/
11622
public function checkToken($clientId, $token = null)
11723
{
118-
$this->configurePreviewHeader();
119-
12024
return $this->post('/applications/'.rawurlencode($clientId).'/token', $token ? ['access_token' => $token] : []);
12125
}
12226

123-
/**
124-
* Reset an authorization.
125-
*
126-
* @param string $clientId
127-
* @param string $token
128-
*
129-
* @return array
130-
*
131-
* @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::resetToken() instead.
132-
*/
133-
public function reset($clientId, $token)
134-
{
135-
return $this->post('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token));
136-
}
137-
13827
/**
13928
* Reset an application token.
14029
*
@@ -145,36 +34,9 @@ public function reset($clientId, $token)
14534
*/
14635
public function resetToken($clientId, $token = null)
14736
{
148-
$this->configurePreviewHeader();
149-
15037
return $this->patch('/applications/'.rawurlencode($clientId).'/token', $token ? ['access_token' => $token] : []);
15138
}
15239

153-
/**
154-
* Remove an authorization.
155-
*
156-
* @param string $clientId
157-
* @param string $token
158-
*
159-
* @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::deleteToken() instead.
160-
*/
161-
public function revoke($clientId, $token)
162-
{
163-
$this->delete('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token));
164-
}
165-
166-
/**
167-
* Revoke all authorizations.
168-
*
169-
* @param string $clientId
170-
*
171-
* @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::deleteGrant() instead.
172-
*/
173-
public function revokeAll($clientId)
174-
{
175-
$this->delete('/applications/'.rawurlencode($clientId).'/tokens');
176-
}
177-
17840
/**
17941
* Revoke an application token.
18042
*
@@ -185,8 +47,6 @@ public function revokeAll($clientId)
18547
*/
18648
public function deleteToken($clientId, $token = null)
18749
{
188-
$this->configurePreviewHeader();
189-
19050
$this->delete('/applications/'.rawurlencode($clientId).'/token', $token ? ['access_token' => $token] : []);
19151
}
19252

@@ -200,8 +60,6 @@ public function deleteToken($clientId, $token = null)
20060
*/
20161
public function deleteGrant($clientId, $token = null)
20262
{
203-
$this->configurePreviewHeader();
204-
20563
$this->delete('/applications/'.rawurlencode($clientId).'/grant', $token ? ['access_token' => $token] : []);
20664
}
20765
}

lib/Github/Api/CurrentUser.php

-20
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,6 @@ public function watchers()
150150
return new Watchers($this->client);
151151
}
152152

153-
/**
154-
* @deprecated Use watchers() instead
155-
*/
156-
public function watched($page = 1)
157-
{
158-
return $this->get('/user/watched', [
159-
'page' => $page,
160-
]);
161-
}
162-
163153
/**
164154
* @return Starring
165155
*/
@@ -168,16 +158,6 @@ public function starring()
168158
return new Starring($this->client);
169159
}
170160

171-
/**
172-
* @deprecated Use starring() instead
173-
*/
174-
public function starred($page = 1)
175-
{
176-
return $this->get('/user/starred', [
177-
'page' => $page,
178-
]);
179-
}
180-
181161
/**
182162
* @link https://developer.github.com/v3/activity/watching/#list-repositories-being-watched
183163
*/

0 commit comments

Comments
 (0)