Skip to content

Commit 93a2d27

Browse files
committed
Compatibility fixes
1 parent 6a6dddc commit 93a2d27

File tree

7 files changed

+45
-10
lines changed

7 files changed

+45
-10
lines changed

lib/Github/HttpClient/Plugin/Authentication.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*/
1515
class Authentication implements Plugin
1616
{
17+
use Plugin\VersionBridgePlugin;
18+
1719
private $tokenOrLogin;
1820
private $password;
1921
private $method;
@@ -28,7 +30,7 @@ public function __construct($tokenOrLogin, $password, $method)
2830
/**
2931
* {@inheritdoc}
3032
*/
31-
public function handleRequest(RequestInterface $request, callable $next, callable $first)
33+
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
3234
{
3335
switch ($this->method) {
3436
case Client::AUTH_HTTP_PASSWORD:

lib/Github/HttpClient/Plugin/GithubExceptionThrower.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
*/
1919
class GithubExceptionThrower implements Plugin
2020
{
21+
use Plugin\VersionBridgePlugin;
22+
2123
/**
2224
* {@inheritdoc}
2325
*/
24-
public function handleRequest(RequestInterface $request, callable $next, callable $first)
26+
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
2527
{
2628
return $next($request)->then(function (ResponseInterface $response) use ($request) {
2729
if ($response->getStatusCode() < 400 || $response->getStatusCode() > 600) {

lib/Github/HttpClient/Plugin/History.php

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

55
use Http\Client\Common\Plugin\Journal;
6-
use Http\Client\Exception;
76
use Psr\Http\Message\RequestInterface;
87
use Psr\Http\Message\ResponseInterface;
98

@@ -14,6 +13,8 @@
1413
*/
1514
class History implements Journal
1615
{
16+
use HistoryTrait;
17+
1718
/**
1819
* @var ResponseInterface
1920
*/
@@ -31,8 +32,4 @@ public function addSuccess(RequestInterface $request, ResponseInterface $respons
3132
{
3233
$this->lastResponse = $response;
3334
}
34-
35-
public function addFailure(RequestInterface $request, Exception $exception)
36-
{
37-
}
3835
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Github\HttpClient\Plugin;
4+
5+
use Http\Client\Exception;
6+
use Psr\Http\Client\ClientExceptionInterface;
7+
use Psr\Http\Message\RequestInterface;
8+
9+
/*
10+
* Below is a some code to make the History plugin compatible with both 1.x and 2.x of php-client/client-common
11+
*/
12+
if (\interface_exists(\Http\Client\Common\HttpMethodsClientInterface::class)) {
13+
/**
14+
* @internal code for php-http/client-common:2.x
15+
*/
16+
trait HistoryTrait
17+
{
18+
public function addFailure(RequestInterface $request, ClientExceptionInterface $exception)
19+
{
20+
}
21+
}
22+
} else {
23+
/**
24+
* @internal code for php-http/client-common:1.x
25+
*/
26+
trait HistoryTrait
27+
{
28+
public function addFailure(RequestInterface $request, Exception $exception)
29+
{
30+
}
31+
}
32+
}

lib/Github/HttpClient/Plugin/PathPrepend.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
class PathPrepend implements Plugin
1414
{
15+
use Plugin\VersionBridgePlugin;
16+
1517
private $path;
1618

1719
/**
@@ -25,7 +27,7 @@ public function __construct($path)
2527
/**
2628
* {@inheritdoc}
2729
*/
28-
public function handleRequest(RequestInterface $request, callable $next, callable $first)
30+
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
2931
{
3032
$currentPath = $request->getUri()->getPath();
3133
if (strpos($currentPath, $this->path) !== 0) {

test/Github/Tests/HttpClient/PathPrependTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testPathIsPrepended($uri, $expectedPath)
2020
$plugin = new PathPrepend('/api/v3');
2121

2222
$newRequest = null;
23-
$plugin->handleRequest($request, function ($request) use (&$newRequest) {
23+
$plugin->doHandleRequest($request, function ($request) use (&$newRequest) {
2424
$newRequest = $request;
2525
}, function () {
2626
throw new \RuntimeException('Did not expect plugin to call first');

test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testHandleRequest(ResponseInterface $response, ExceptionInterfac
4040
$this->expectExceptionMessage($exception->getMessage());
4141
}
4242

43-
$plugin->handleRequest(
43+
$plugin->doHandleRequest(
4444
$request,
4545
function (RequestInterface $request) use ($promise) {
4646
return $promise;

0 commit comments

Comments
 (0)