Update to laravel 7

This commit is contained in:
KodeStar
2022-03-10 11:54:29 +00:00
parent 61a5a1a8b0
commit f9a19fce91
7170 changed files with 274189 additions and 283773 deletions

View File

@@ -1,34 +1,34 @@
<?php
declare(strict_types=1);
namespace Http\Client\Common;
use Http\Client\Exception\RequestException;
use Http\Client\Common\Exception\HttpClientNoMatchException;
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;
/**
* Route a request to a specific client in the stack based using a RequestMatcher.
* {@inheritdoc}
*
* @author Joel Wurtz <joel.wurtz@gmail.com>
*/
final class HttpClientRouter implements HttpClient, HttpAsyncClient
final class HttpClientRouter implements HttpClientRouterInterface
{
/**
* @var array
* @var (array{matcher: RequestMatcher, client: FlexibleHttpClient})[]
*/
private $clients = [];
/**
* {@inheritdoc}
*/
public function sendRequest(RequestInterface $request)
public function sendRequest(RequestInterface $request): ResponseInterface
{
$client = $this->chooseHttpClient($request);
return $client->sendRequest($request);
return $this->chooseHttpClient($request)->sendRequest($request);
}
/**
@@ -36,19 +36,22 @@ final class HttpClientRouter implements HttpClient, HttpAsyncClient
*/
public function sendAsyncRequest(RequestInterface $request)
{
$client = $this->chooseHttpClient($request);
return $client->sendAsyncRequest($request);
return $this->chooseHttpClient($request)->sendAsyncRequest($request);
}
/**
* Add a client to the router.
*
* @param HttpClient|HttpAsyncClient|ClientInterface $client
* @param RequestMatcher $requestMatcher
* @param ClientInterface|HttpAsyncClient $client
*/
public function addClient($client, RequestMatcher $requestMatcher)
public function addClient($client, RequestMatcher $requestMatcher): void
{
if (!$client instanceof ClientInterface && !$client instanceof HttpAsyncClient) {
throw new \TypeError(
sprintf('%s::addClient(): Argument #1 ($client) must be of type %s|%s, %s given', self::class, ClientInterface::class, HttpAsyncClient::class, get_debug_type($client))
);
}
$this->clients[] = [
'matcher' => $requestMatcher,
'client' => new FlexibleHttpClient($client),
@@ -57,12 +60,8 @@ final class HttpClientRouter implements HttpClient, HttpAsyncClient
/**
* Choose an HTTP client given a specific request.
*
* @param RequestInterface $request
*
* @return HttpClient|HttpAsyncClient|ClientInterface
*/
protected function chooseHttpClient(RequestInterface $request)
private function chooseHttpClient(RequestInterface $request): FlexibleHttpClient
{
foreach ($this->clients as $client) {
if ($client['matcher']->matches($request)) {
@@ -70,6 +69,6 @@ final class HttpClientRouter implements HttpClient, HttpAsyncClient
}
}
throw new RequestException('No client found for the specified request', $request);
throw new HttpClientNoMatchException('No client found for the specified request', $request);
}
}