Skip to content

Commit

Permalink
Support httplug v2 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell authored Nov 3, 2019
1 parent ee2d25f commit a25c527
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 21 deletions.
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,32 @@ matrix:
include:
- env:
- PHP_VERSION=7.1
- HTTPPLUG_VERSION=^1.1
- env:
- PHP_VERSION=7.1
- HTTPPLUG_VERSION=^2.0
- env:
- PHP_VERSION=7.2
- HTTPPLUG_VERSION=^1.1
- env:
- PHP_VERSION=7.2
- HTTPPLUG_VERSION=^2.0
- env:
- PHP_VERSION=7.3
- HTTPPLUG_VERSION=^1.1
- env:
- PHP_VERSION=7.3
- HTTPPLUG_VERSION=^2.0
- env:
- PHP_VERSION=7.4
- HTTPPLUG_VERSION=^1.1
- env:
- PHP_VERSION=7.4
- HTTPPLUG_VERSION=^2.0

before_install:
- travis_retry docker pull registry.gitlab.com/grahamcampbell/php:$PHP_VERSION
- docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint composer registry.gitlab.com/grahamcampbell/php:$PHP_VERSION require "php-http/httplug:${HTTPPLUG_VERSION}" --no-update -n

install:
- travis_retry docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint composer registry.gitlab.com/grahamcampbell/php:$PHP_VERSION install --no-suggest --prefer-dist -n -o
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ This version requires [PHP](https://php.net) 7.1-7.4.
To get the latest version, simply require the project using [Composer](https://getcomposer.org). You will need to install any package that "provides" `php-http/client-implementation`. Most users will want:

```bash
$ composer require bitbucket/client php-http/guzzle6-adapter:^1.1
$ composer require bitbucket/client php-http/guzzle6-adapter:^2.0
```

There is also a Laravel bridge for this package: [`graham-campbell/bitbucket`](https://github.com/GrahamCampbell/Laravel-Bitbucket).

## Usage

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
"php": "^7.1.3",
"psr/http-message": "^1.0",
"psr/cache": "^1.0",
"php-http/httplug": "^1.1",
"php-http/httplug": "^1.1|^2.0",
"php-http/discovery": "^1.6",
"php-http/cache-plugin": "^1.6",
"php-http/client-implementation": "^1.0",
"php-http/client-common": "^1.9",
"php-http/client-common": "^1.9|^2.0",
"php-http/multipart-stream-builder": "^1.0"
},
"require-dev": {
"graham-campbell/analyzer": "^2.1",
"phpunit/phpunit": "^7.0|^8.0",
"php-http/guzzle6-adapter": "^1.1"
"php-http/guzzle6-adapter": "^1.1|^2.0"
},
"autoload": {
"psr-4": {
Expand All @@ -40,7 +40,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
"dev-master": "2.1-dev"
}
},
"minimum-stability": "dev",
Expand Down
4 changes: 3 additions & 1 deletion src/HttpClient/Plugin/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*/
class Authentication implements Plugin
{
use Plugin\VersionBridgePlugin;

/**
* The authorization header.
*
Expand Down Expand Up @@ -56,7 +58,7 @@ public function __construct(string $method, string $token, string $password = nu
*
* @return \Http\Promise\Promise
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first)
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
{
$request = $request->withHeader('Authorization', $this->header);

Expand Down
4 changes: 3 additions & 1 deletion src/HttpClient/Plugin/ExceptionThrower.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
*/
class ExceptionThrower implements Plugin
{
use Plugin\VersionBridgePlugin;

/**
* Handle the request and return the response coming from the next callable.
*
Expand All @@ -42,7 +44,7 @@ class ExceptionThrower implements Plugin
*
* @return \Http\Promise\Promise
*/
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) {
$status = $response->getStatusCode();
Expand Down
16 changes: 2 additions & 14 deletions src/HttpClient/Plugin/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace Bitbucket\HttpClient\Plugin;

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

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

/**
* The last response.
*
Expand Down Expand Up @@ -55,17 +56,4 @@ public function addSuccess(RequestInterface $request, ResponseInterface $respons
{
$this->lastResponse = $response;
}

/**
* Record a failed call.
*
* @param \Psr\Http\Message\RequestInterface $request
* @param \Http\Client\Exception $exception
*
* @return void
*/
public function addFailure(RequestInterface $request, Exception $exception)
{
// do nothing
}
}
35 changes: 35 additions & 0 deletions src/HttpClient/Plugin/HistoryTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

/*
* This file is part of Bitbucket API Client.
*
* (c) Graham Campbell <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Bitbucket\HttpClient\Plugin;

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

if (interface_exists(HttpMethodsClientInterface::class)) {
trait HistoryTrait
{
public function addFailure(RequestInterface $request, ClientExceptionInterface $exception)
{
}
}
} else {
trait HistoryTrait
{
public function addFailure(RequestInterface $request, Exception $exception)
{
}
}
}
12 changes: 12 additions & 0 deletions tests/AnalysisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
namespace Bitbucket\Tests;

use GrahamCampbell\Analyzer\AnalysisTrait;
use Http\Client\Common\HttpMethodsClientInterface;
use PHPUnit\Framework\TestCase;
use Psr\Http\Client\ClientExceptionInterface;

/**
* This is the analysis test class.
Expand All @@ -37,4 +39,14 @@ protected function getPaths()
realpath(__DIR__),
];
}

/**
* Get the classes to ignore not existing.
*
* @return string[]
*/
protected function getIgnored()
{
return [ClientExceptionInterface::class, HttpMethodsClientInterface::class];
}
}

0 comments on commit a25c527

Please sign in to comment.