diff --git a/src/BatchClient.php b/src/BatchClient.php index 09a83ff..b1cbe8d 100644 --- a/src/BatchClient.php +++ b/src/BatchClient.php @@ -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; } diff --git a/src/EmulatedHttpAsyncClient.php b/src/EmulatedHttpAsyncClient.php index 9d6c557..d669f25 100644 --- a/src/EmulatedHttpAsyncClient.php +++ b/src/EmulatedHttpAsyncClient.php @@ -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. @@ -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; } diff --git a/src/FlexibleHttpClient.php b/src/FlexibleHttpClient.php index 58f8813..23d6e9f 100644 --- a/src/FlexibleHttpClient.php +++ b/src/FlexibleHttpClient.php @@ -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 @@ -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); } diff --git a/src/HttpClientDecorator.php b/src/HttpClientDecorator.php index da5a1bb..9e5724c 100644 --- a/src/HttpClientDecorator.php +++ b/src/HttpClientDecorator.php @@ -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; @@ -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 { diff --git a/src/HttpClientPool.php b/src/HttpClientPool.php index a730f50..c71f9f9 100644 --- a/src/HttpClientPool.php +++ b/src/HttpClientPool.php @@ -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, @@ -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); } diff --git a/src/HttpClientPool/HttpClientPool.php b/src/HttpClientPool/HttpClientPool.php index cbac805..8e2ce64 100644 --- a/src/HttpClientPool/HttpClientPool.php +++ b/src/HttpClientPool/HttpClientPool.php @@ -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; @@ -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) { diff --git a/src/HttpClientPool/HttpClientPoolItem.php b/src/HttpClientPool/HttpClientPoolItem.php index 4094502..0b382cb 100644 --- a/src/HttpClientPool/HttpClientPoolItem.php +++ b/src/HttpClientPool/HttpClientPoolItem.php @@ -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; @@ -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) { diff --git a/src/HttpClientRouter.php b/src/HttpClientRouter.php index 56be0bf..9008156 100644 --- a/src/HttpClientRouter.php +++ b/src/HttpClientRouter.php @@ -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; @@ -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) { diff --git a/src/HttpClientRouterInterface.php b/src/HttpClientRouterInterface.php index 67fb822..635e25e 100644 --- a/src/HttpClientRouterInterface.php +++ b/src/HttpClientRouterInterface.php @@ -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. @@ -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); } diff --git a/src/HttpMethodsClient.php b/src/HttpMethodsClient.php index 69e4df9..e4ab0f6 100644 --- a/src/HttpMethodsClient.php +++ b/src/HttpMethodsClient.php @@ -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; @@ -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; diff --git a/src/Plugin/AddPathPlugin.php b/src/Plugin/AddPathPlugin.php index 0a2adba..3b7dcaf 100644 --- a/src/Plugin/AddPathPlugin.php +++ b/src/Plugin/AddPathPlugin.php @@ -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; } diff --git a/src/PluginClient.php b/src/PluginClient.php index 264c2fe..4c95300 100644 --- a/src/PluginClient.php +++ b/src/PluginClient.php @@ -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; @@ -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 * } @@ -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; diff --git a/src/PluginClientFactory.php b/src/PluginClientFactory.php index 77642ea..b4a78fc 100644 --- a/src/PluginClientFactory.php +++ b/src/PluginClientFactory.php @@ -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 @@ -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.