Skip to content

Commit a25c527

Browse files
Support httplug v2 (#28)
1 parent ee2d25f commit a25c527

File tree

8 files changed

+78
-21
lines changed

8 files changed

+78
-21
lines changed

.travis.yml

+17
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,32 @@ matrix:
44
include:
55
- env:
66
- PHP_VERSION=7.1
7+
- HTTPPLUG_VERSION=^1.1
8+
- env:
9+
- PHP_VERSION=7.1
10+
- HTTPPLUG_VERSION=^2.0
11+
- env:
12+
- PHP_VERSION=7.2
13+
- HTTPPLUG_VERSION=^1.1
714
- env:
815
- PHP_VERSION=7.2
16+
- HTTPPLUG_VERSION=^2.0
917
- env:
1018
- PHP_VERSION=7.3
19+
- HTTPPLUG_VERSION=^1.1
20+
- env:
21+
- PHP_VERSION=7.3
22+
- HTTPPLUG_VERSION=^2.0
23+
- env:
24+
- PHP_VERSION=7.4
25+
- HTTPPLUG_VERSION=^1.1
1126
- env:
1227
- PHP_VERSION=7.4
28+
- HTTPPLUG_VERSION=^2.0
1329

1430
before_install:
1531
- travis_retry docker pull registry.gitlab.com/grahamcampbell/php:$PHP_VERSION
32+
- 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
1633

1734
install:
1835
- 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

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ This version requires [PHP](https://php.net) 7.1-7.4.
1616
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:
1717

1818
```bash
19-
$ composer require bitbucket/client php-http/guzzle6-adapter:^1.1
19+
$ composer require bitbucket/client php-http/guzzle6-adapter:^2.0
2020
```
2121

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

2324
## Usage
2425

composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
"php": "^7.1.3",
1414
"psr/http-message": "^1.0",
1515
"psr/cache": "^1.0",
16-
"php-http/httplug": "^1.1",
16+
"php-http/httplug": "^1.1|^2.0",
1717
"php-http/discovery": "^1.6",
1818
"php-http/cache-plugin": "^1.6",
1919
"php-http/client-implementation": "^1.0",
20-
"php-http/client-common": "^1.9",
20+
"php-http/client-common": "^1.9|^2.0",
2121
"php-http/multipart-stream-builder": "^1.0"
2222
},
2323
"require-dev": {
2424
"graham-campbell/analyzer": "^2.1",
2525
"phpunit/phpunit": "^7.0|^8.0",
26-
"php-http/guzzle6-adapter": "^1.1"
26+
"php-http/guzzle6-adapter": "^1.1|^2.0"
2727
},
2828
"autoload": {
2929
"psr-4": {
@@ -40,7 +40,7 @@
4040
},
4141
"extra": {
4242
"branch-alias": {
43-
"dev-master": "2.0-dev"
43+
"dev-master": "2.1-dev"
4444
}
4545
},
4646
"minimum-stability": "dev",

src/HttpClient/Plugin/Authentication.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
*/
2727
class Authentication implements Plugin
2828
{
29+
use Plugin\VersionBridgePlugin;
30+
2931
/**
3032
* The authorization header.
3133
*
@@ -56,7 +58,7 @@ public function __construct(string $method, string $token, string $password = nu
5658
*
5759
* @return \Http\Promise\Promise
5860
*/
59-
public function handleRequest(RequestInterface $request, callable $next, callable $first)
61+
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
6062
{
6163
$request = $request->withHeader('Authorization', $this->header);
6264

src/HttpClient/Plugin/ExceptionThrower.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
*/
3434
class ExceptionThrower implements Plugin
3535
{
36+
use Plugin\VersionBridgePlugin;
37+
3638
/**
3739
* Handle the request and return the response coming from the next callable.
3840
*
@@ -42,7 +44,7 @@ class ExceptionThrower implements Plugin
4244
*
4345
* @return \Http\Promise\Promise
4446
*/
45-
public function handleRequest(RequestInterface $request, callable $next, callable $first)
47+
public function doHandleRequest(RequestInterface $request, callable $next, callable $first)
4648
{
4749
return $next($request)->then(function (ResponseInterface $response) {
4850
$status = $response->getStatusCode();

src/HttpClient/Plugin/History.php

+2-14
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace Bitbucket\HttpClient\Plugin;
1515

1616
use Http\Client\Common\Plugin\Journal;
17-
use Http\Client\Exception;
1817
use Psr\Http\Message\RequestInterface;
1918
use Psr\Http\Message\ResponseInterface;
2019

@@ -26,6 +25,8 @@
2625
*/
2726
class History implements Journal
2827
{
28+
use HistoryTrait;
29+
2930
/**
3031
* The last response.
3132
*
@@ -55,17 +56,4 @@ public function addSuccess(RequestInterface $request, ResponseInterface $respons
5556
{
5657
$this->lastResponse = $response;
5758
}
58-
59-
/**
60-
* Record a failed call.
61-
*
62-
* @param \Psr\Http\Message\RequestInterface $request
63-
* @param \Http\Client\Exception $exception
64-
*
65-
* @return void
66-
*/
67-
public function addFailure(RequestInterface $request, Exception $exception)
68-
{
69-
// do nothing
70-
}
7159
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of Bitbucket API Client.
7+
*
8+
* (c) Graham Campbell <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Bitbucket\HttpClient\Plugin;
15+
16+
use Http\Client\Common\HttpMethodsClientInterface;
17+
use Http\Client\Exception;
18+
use Psr\Http\Client\ClientExceptionInterface;
19+
use Psr\Http\Message\RequestInterface;
20+
21+
if (interface_exists(HttpMethodsClientInterface::class)) {
22+
trait HistoryTrait
23+
{
24+
public function addFailure(RequestInterface $request, ClientExceptionInterface $exception)
25+
{
26+
}
27+
}
28+
} else {
29+
trait HistoryTrait
30+
{
31+
public function addFailure(RequestInterface $request, Exception $exception)
32+
{
33+
}
34+
}
35+
}

tests/AnalysisTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
namespace Bitbucket\Tests;
1515

1616
use GrahamCampbell\Analyzer\AnalysisTrait;
17+
use Http\Client\Common\HttpMethodsClientInterface;
1718
use PHPUnit\Framework\TestCase;
19+
use Psr\Http\Client\ClientExceptionInterface;
1820

1921
/**
2022
* This is the analysis test class.
@@ -37,4 +39,14 @@ protected function getPaths()
3739
realpath(__DIR__),
3840
];
3941
}
42+
43+
/**
44+
* Get the classes to ignore not existing.
45+
*
46+
* @return string[]
47+
*/
48+
protected function getIgnored()
49+
{
50+
return [ClientExceptionInterface::class, HttpMethodsClientInterface::class];
51+
}
4052
}

0 commit comments

Comments
 (0)