Skip to content

Commit d7f2e34

Browse files
committed
Added backwards compatibility layer
1 parent b4d5bbc commit d7f2e34

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/Plugin/VersionBridgePlugin.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Http\Client\Common\Plugin;
4+
5+
use Http\Client\Common\Plugin;
6+
use Http\Promise\Promise;
7+
use Psr\Http\Message\RequestInterface;
8+
9+
/**
10+
* A plugin that helps you migrate from php-http/client-common 1.x to 2.x. This
11+
* will also help you to support PHP5 at the same time you support 2.x.
12+
*
13+
* @author Tobias Nyholm <[email protected]>
14+
*/
15+
abstract class VersionBridgePlugin implements Plugin
16+
{
17+
abstract protected function doHandleRequest(RequestInterface $request, callable $next, callable $first);
18+
19+
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
20+
{
21+
return $this->doHandleRequest($request, $next, $first);
22+
}
23+
}

src/VersionBridgeClient.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Http\Client\Common;
4+
5+
use Http\Client\HttpClient;
6+
use Psr\Http\Message\RequestInterface;
7+
use Psr\Http\Message\ResponseInterface;
8+
9+
/**
10+
* A client that helps you migrate from php-http/httplug 1.x to 2.x. This
11+
* will also help you to support PHP5 at the same time you support 2.x.
12+
*
13+
* @author Tobias Nyholm <[email protected]>
14+
*/
15+
abstract class VersionBridgeClient implements HttpClient
16+
{
17+
abstract protected function doSendRequest(RequestInterface $request);
18+
19+
public function sendRequest(RequestInterface $request): ResponseInterface
20+
{
21+
return $this->doSendRequest($request);
22+
}
23+
}

0 commit comments

Comments
 (0)