Skip to content

Commit 0eeac12

Browse files
Nyholmjbelien
authored andcommitted
Make sure we support PSR-18 (#16)
* Make sure we support PSR-18 * Added file header * Update HttpClientTrait.php StyleCI fix
1 parent b4d46f0 commit 0eeac12

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
"require": {
1717
"php": "^7.1",
1818
"phpunit/phpunit": "^7.5",
19-
"psr/http-message-implementation": "^1.0",
20-
"php-http/mock-client": "^1.1",
19+
"php-http/mock-client": "^1.2",
2120
"nyholm/psr7": "^1.0.0"
2221
},
2322
"require-dev": {

src/CachedResponseClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
class CachedResponseClient implements HttpClient
2424
{
25+
use HttpClientTrait;
26+
2527
/**
2628
* @var HttpClient
2729
*/
@@ -59,7 +61,7 @@ public function __construct(HttpClient $delegate, $cacheDir, $apiKey = null, $ap
5961
/**
6062
* {@inheritdoc}
6163
*/
62-
public function sendRequest(RequestInterface $request)
64+
protected function doSendRequest(RequestInterface $request)
6365
{
6466
$host = (string) $request->getUri()->getHost();
6567
$cacheKey = (string) $request->getUri();

src/HttpClientTrait.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Geocoder package.
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*
10+
* @license MIT License
11+
*/
12+
13+
namespace Geocoder\IntegrationTest;
14+
15+
use Psr\Http\Client\ClientInterface;
16+
use Psr\Http\Message\RequestInterface;
17+
use Psr\Http\Message\ResponseInterface;
18+
19+
/*
20+
* This test is not 100% perfect. You may have installed HTTPlug:1.x and PSR-18.
21+
*/
22+
if (\interface_exists(ClientInterface::class)) {
23+
/**
24+
* @internal code for php-http/httplug:2.x
25+
*/
26+
trait HttpClientTrait
27+
{
28+
abstract protected function doSendRequest(RequestInterface $request);
29+
30+
public function sendRequest(RequestInterface $request): ResponseInterface
31+
{
32+
return $this->doSendRequest($request);
33+
}
34+
}
35+
} else {
36+
/**
37+
* @internal code for php-http/httplug:1.x
38+
*/
39+
trait HttpClientTrait
40+
{
41+
abstract protected function doSendRequest(RequestInterface $request);
42+
43+
public function sendRequest(RequestInterface $request)
44+
{
45+
return $this->doSendRequest($request);
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)