Skip to content

Commit

Permalink
Compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
acrobat committed Aug 8, 2019
1 parent 6a6dddc commit 93a2d27
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
4 changes: 3 additions & 1 deletion lib/Github/HttpClient/Plugin/Authentication.php
Expand Up @@ -14,6 +14,8 @@
*/
class Authentication implements Plugin
{
use Plugin\VersionBridgePlugin;

private $tokenOrLogin;
private $password;
private $method;
Expand All @@ -28,7 +30,7 @@ public function __construct($tokenOrLogin, $password, $method)
/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first)
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
{
switch ($this->method) {
case Client::AUTH_HTTP_PASSWORD:
Expand Down
4 changes: 3 additions & 1 deletion lib/Github/HttpClient/Plugin/GithubExceptionThrower.php
Expand Up @@ -18,10 +18,12 @@
*/
class GithubExceptionThrower implements Plugin
{
use Plugin\VersionBridgePlugin;

/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first)
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
{
return $next($request)->then(function (ResponseInterface $response) use ($request) {
if ($response->getStatusCode() < 400 || $response->getStatusCode() > 600) {
Expand Down
7 changes: 2 additions & 5 deletions lib/Github/HttpClient/Plugin/History.php
Expand Up @@ -3,7 +3,6 @@
namespace Github\HttpClient\Plugin;

use Http\Client\Common\Plugin\Journal;
use Http\Client\Exception;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

Expand All @@ -14,6 +13,8 @@
*/
class History implements Journal
{
use HistoryTrait;

/**
* @var ResponseInterface
*/
Expand All @@ -31,8 +32,4 @@ public function addSuccess(RequestInterface $request, ResponseInterface $respons
{
$this->lastResponse = $response;
}

public function addFailure(RequestInterface $request, Exception $exception)
{
}
}
32 changes: 32 additions & 0 deletions lib/Github/HttpClient/Plugin/HistoryTrait.php
@@ -0,0 +1,32 @@
<?php

namespace Github\HttpClient\Plugin;

use Http\Client\Exception;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Message\RequestInterface;

/*
* Below is a some code to make the History plugin compatible with both 1.x and 2.x of php-client/client-common
*/
if (\interface_exists(\Http\Client\Common\HttpMethodsClientInterface::class)) {
/**
* @internal code for php-http/client-common:2.x
*/
trait HistoryTrait
{
public function addFailure(RequestInterface $request, ClientExceptionInterface $exception)
{
}
}
} else {
/**
* @internal code for php-http/client-common:1.x
*/
trait HistoryTrait
{
public function addFailure(RequestInterface $request, Exception $exception)
{
}
}
}
4 changes: 3 additions & 1 deletion lib/Github/HttpClient/Plugin/PathPrepend.php
Expand Up @@ -12,6 +12,8 @@
*/
class PathPrepend implements Plugin
{
use Plugin\VersionBridgePlugin;

private $path;

/**
Expand All @@ -25,7 +27,7 @@ public function __construct($path)
/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first)
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
{
$currentPath = $request->getUri()->getPath();
if (strpos($currentPath, $this->path) !== 0) {
Expand Down
2 changes: 1 addition & 1 deletion test/Github/Tests/HttpClient/PathPrependTest.php
Expand Up @@ -20,7 +20,7 @@ public function testPathIsPrepended($uri, $expectedPath)
$plugin = new PathPrepend('/api/v3');

$newRequest = null;
$plugin->handleRequest($request, function ($request) use (&$newRequest) {
$plugin->doHandleRequest($request, function ($request) use (&$newRequest) {
$newRequest = $request;
}, function () {
throw new \RuntimeException('Did not expect plugin to call first');
Expand Down
Expand Up @@ -40,7 +40,7 @@ public function testHandleRequest(ResponseInterface $response, ExceptionInterfac
$this->expectExceptionMessage($exception->getMessage());
}

$plugin->handleRequest(
$plugin->doHandleRequest(
$request,
function (RequestInterface $request) use ($promise) {
return $promise;
Expand Down

0 comments on commit 93a2d27

Please sign in to comment.