Skip to content

Support PSR-18 #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/BatchClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
namespace Http\Client\Common;

use Http\Client\Exception;
use Http\Client\HttpClient;
use Http\Client\Common\Exception\BatchException;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

final class BatchClient implements BatchClientInterface
{
/**
* @var HttpClient
* @var ClientInterface
*/
private $client;

public function __construct(HttpClient $client)
public function __construct(ClientInterface $client)
{
$this->client = $client;
}
Expand Down
3 changes: 2 additions & 1 deletion src/EmulatedHttpAsyncClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Psr\Http\Client\ClientInterface;

/**
* Emulates an async HTTP client with the help of a synchronous client.
Expand All @@ -15,7 +16,7 @@ final class EmulatedHttpAsyncClient implements HttpClient, HttpAsyncClient
use HttpAsyncClientEmulator;
use HttpClientDecorator;

public function __construct(HttpClient $httpClient)
public function __construct(ClientInterface $httpClient)
{
$this->httpClient = $httpClient;
}
Expand Down
9 changes: 5 additions & 4 deletions src/FlexibleHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Psr\Http\Client\ClientInterface;

/**
* A flexible http client, which implements both interface and will emulate
Expand All @@ -17,18 +18,18 @@ final class FlexibleHttpClient implements HttpClient, HttpAsyncClient
use HttpAsyncClientDecorator;

/**
* @param HttpClient|HttpAsyncClient $client
* @param ClientInterface|HttpAsyncClient $client
*/
public function __construct($client)
{
if (!($client instanceof HttpClient) && !($client instanceof HttpAsyncClient)) {
throw new \LogicException('Client must be an instance of Http\\Client\\HttpClient or Http\\Client\\HttpAsyncClient');
if (!($client instanceof ClientInterface) && !($client instanceof HttpAsyncClient)) {
throw new \LogicException('Client must be an instance of Psr\\Http\\Client\\ClientInterface or Http\\Client\\HttpAsyncClient');
}

$this->httpClient = $client;
$this->httpAsyncClient = $client;

if (!($this->httpClient instanceof HttpClient)) {
if (!($this->httpClient instanceof ClientInterface)) {
$this->httpClient = new EmulatedHttpClient($this->httpClient);
}

Expand Down
6 changes: 3 additions & 3 deletions src/HttpClientDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Http\Client\Common;

use Http\Client\HttpClient;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

Expand All @@ -14,14 +14,14 @@
trait HttpClientDecorator
{
/**
* @var HttpClient
* @var ClientInterface
*/
protected $httpClient;

/**
* {@inheritdoc}
*
* @see HttpClient::sendRequest
* @see ClientInterface::sendRequest
*/
public function sendRequest(RequestInterface $request): ResponseInterface
{
Expand Down
3 changes: 2 additions & 1 deletion src/HttpClientPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Http\Client\Common\HttpClientPool\HttpClientPoolItem;
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Psr\Http\Client\ClientInterface;

/**
* A http client pool allows to send requests on a pool of different http client using a specific strategy (least used,
Expand All @@ -15,7 +16,7 @@ interface HttpClientPool extends HttpAsyncClient, HttpClient
/**
* Add a client to the pool.
*
* @param HttpClient|HttpAsyncClient|HttpClientPoolItem $client
* @param ClientInterface|HttpAsyncClient|HttpClientPoolItem $client
*/
public function addHttpClient($client);
}
4 changes: 2 additions & 2 deletions src/HttpClientPool/HttpClientPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Http\Client\Common\Exception\HttpClientNotFoundException;
use Http\Client\Common\HttpClientPool as HttpClientPoolInterface;
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

Expand All @@ -23,7 +23,7 @@ abstract class HttpClientPool implements HttpClientPoolInterface
/**
* Add a client to the pool.
*
* @param HttpClient|HttpAsyncClient|HttpClientPoolItem $client
* @param ClientInterface|HttpAsyncClient|HttpClientPoolItem $client
*/
public function addHttpClient($client)
{
Expand Down
5 changes: 3 additions & 2 deletions src/HttpClientPool/HttpClientPoolItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Http\Client\Common\FlexibleHttpClient;
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Http\Client\Exception;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -51,8 +52,8 @@ class HttpClientPoolItem implements HttpClient, HttpAsyncClient
private $client;

/**
* @param HttpClient|HttpAsyncClient $client
* @param null|int $reenableAfter Number of seconds until this client is enabled again after an error
* @param ClientInterface|HttpAsyncClient $client
* @param null|int $reenableAfter Number of seconds until this client is enabled again after an error
*/
public function __construct($client, $reenableAfter = null)
{
Expand Down
3 changes: 2 additions & 1 deletion src/HttpClientRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Http\Message\RequestMatcher;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

Expand Down Expand Up @@ -53,7 +54,7 @@ public function addClient($client, RequestMatcher $requestMatcher)
/**
* Choose an HTTP client given a specific request.
*
* @return HttpClient|HttpAsyncClient
* @return ClientInterface|HttpAsyncClient
*/
private function chooseHttpClient(RequestInterface $request)
{
Expand Down
3 changes: 2 additions & 1 deletion src/HttpClientRouterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Http\Message\RequestMatcher;
use Psr\Http\Client\ClientInterface;

/**
* Route a request to a specific client in the stack based using a RequestMatcher.
Expand All @@ -18,7 +19,7 @@ interface HttpClientRouterInterface extends HttpClient, HttpAsyncClient
/**
* Add a client to the router.
*
* @param HttpClient|HttpAsyncClient $client
* @param ClientInterface|HttpAsyncClient $client
*/
public function addClient($client, RequestMatcher $requestMatcher);
}
10 changes: 5 additions & 5 deletions src/HttpMethodsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Http\Client\Common;

use Http\Client\HttpClient;
use Http\Message\RequestFactory;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

final class HttpMethodsClient implements HttpMethodsClientInterface
{
/**
* @var HttpClient
* @var ClientInterface
*/
private $httpClient;

Expand All @@ -20,10 +20,10 @@ final class HttpMethodsClient implements HttpMethodsClientInterface
private $requestFactory;

/**
* @param HttpClient $httpClient The client to send requests with
* @param RequestFactory $requestFactory The message factory to create requests
* @param ClientInterface $httpClient The client to send requests with
* @param RequestFactory $requestFactory The message factory to create requests
*/
public function __construct(HttpClient $httpClient, RequestFactory $requestFactory)
public function __construct(ClientInterface $httpClient, RequestFactory $requestFactory)
{
$this->httpClient = $httpClient;
$this->requestFactory = $requestFactory;
Expand Down
5 changes: 2 additions & 3 deletions src/Plugin/AddPathPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
$identifier = spl_object_hash((object) $first);

if (!array_key_exists($identifier, $this->alteredRequests)) {
$request = $request->withUri($request->getUri()
->withPath($this->uri->getPath().$request->getUri()->getPath())
);
$prefixedUrl = $this->uri->getPath().$request->getUri()->getPath();
$request = $request->withUri($request->getUri()->withPath($prefixedUrl));
$this->alteredRequests[$identifier] = $identifier;
}

Expand Down
11 changes: 6 additions & 5 deletions src/PluginClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Http\Client\HttpClient;
use Http\Client\Promise\HttpFulfilledPromise;
use Http\Client\Promise\HttpRejectedPromise;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
Expand Down Expand Up @@ -41,9 +42,9 @@ final class PluginClient implements HttpClient, HttpAsyncClient
private $options;

/**
* @param HttpClient|HttpAsyncClient $client
* @param Plugin[] $plugins
* @param array $options {
* @param ClientInterface|HttpAsyncClient $client
* @param Plugin[] $plugins
* @param array $options {
*
* @var int $max_restarts
* }
Expand All @@ -54,10 +55,10 @@ public function __construct($client, array $plugins = [], array $options = [])
{
if ($client instanceof HttpAsyncClient) {
$this->client = $client;
} elseif ($client instanceof HttpClient) {
} elseif ($client instanceof ClientInterface) {
$this->client = new EmulatedHttpAsyncClient($client);
} else {
throw new \RuntimeException('Client must be an instance of Http\\Client\\HttpClient or Http\\Client\\HttpAsyncClient');
throw new \RuntimeException('Client must be an instance of Psr\\Http\\Client\\ClientInterface or Http\\Client\\HttpAsyncClient');
}

$this->plugins = $plugins;
Expand Down
8 changes: 4 additions & 4 deletions src/PluginClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Http\Client\Common;

use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Psr\Http\Client\ClientInterface;

/**
* Factory to create PluginClient instances. Using this factory instead of calling PluginClient constructor will enable
Expand Down Expand Up @@ -33,9 +33,9 @@ public static function setFactory(callable $factory)
}

/**
* @param HttpClient|HttpAsyncClient $client
* @param Plugin[] $plugins
* @param array $options {
* @param ClientInterface|HttpAsyncClient $client
* @param Plugin[] $plugins
* @param array $options {
*
* @var string $client_name to give client a name which may be used when displaying client information like in
* the HTTPlugBundle profiler.
Expand Down