From 790440627956b2baccafe516f564670a5bacb970 Mon Sep 17 00:00:00 2001 From: m-yamagishi Date: Wed, 6 Sep 2023 07:31:50 +0900 Subject: [PATCH] wip: modified ClientFactory --- src/HttpClient/AmphpClient.php | 2 +- src/HttpClient/BuzzClient.php | 4 -- src/HttpClient/ClientFactory.php | 8 ++- src/Support/DefaultHttpBuilder.php | 88 ------------------------------ 4 files changed, 8 insertions(+), 94 deletions(-) delete mode 100644 src/Support/DefaultHttpBuilder.php diff --git a/src/HttpClient/AmphpClient.php b/src/HttpClient/AmphpClient.php index 0d1fee2..cf3e9c8 100644 --- a/src/HttpClient/AmphpClient.php +++ b/src/HttpClient/AmphpClient.php @@ -24,7 +24,7 @@ */ final class AmphpClient implements HttpClientInterface { - /** @var Closure[] $middlewares */ + /** @var list $middlewares */ private array $middlewares = []; public function __construct( diff --git a/src/HttpClient/BuzzClient.php b/src/HttpClient/BuzzClient.php index e69da20..ae30887 100644 --- a/src/HttpClient/BuzzClient.php +++ b/src/HttpClient/BuzzClient.php @@ -11,7 +11,6 @@ use Buzz\Client\BuzzClientInterface; use Closure; use Heavyrain\Contracts\ClientInterface; -use Heavyrain\Executor\Middlewares\IdentifyRequestMiddleware; use Heavyrain\Executor\Middlewares\ProfilingMiddleware; use Heavyrain\Executor\Middlewares\WaitSendRequestMiddleware; use Heavyrain\Scenario\Client; @@ -43,9 +42,6 @@ public function createClient(?BuzzClientInterface $buzzClient = null): ClientInt 'verify' => $this->config->sslVerify, 'timeout' => $this->config->timeout, ]); - // TODO: implement uniqid every client - $clientId = \uniqid(); - $client->addMiddleware(new IdentifyRequestMiddleware($clientId)); $client->addMiddleware(new ProfilingMiddleware($this->profiler)); $client->addMiddleware(new WaitSendRequestMiddleware($this->config->waitAfterSendRequestSec)); diff --git a/src/HttpClient/ClientFactory.php b/src/HttpClient/ClientFactory.php index 7135245..bbeee77 100644 --- a/src/HttpClient/ClientFactory.php +++ b/src/HttpClient/ClientFactory.php @@ -18,10 +18,16 @@ use Laminas\Diactoros\UriFactory; /** - * Client factory + * A factory for creating HTTP clients. */ final class ClientFactory { + /** + * Creates a new HTTP client instance with the specified base URI. + * + * @param string $baseUri The base URI for the HTTP client. + * @return ClientInterface The newly created HTTP client instance. + */ public static function create(string $baseUri): ClientInterface { $ampHttpClient = (new HttpClientBuilder()) diff --git a/src/Support/DefaultHttpBuilder.php b/src/Support/DefaultHttpBuilder.php deleted file mode 100644 index 7d30149..0000000 --- a/src/Support/DefaultHttpBuilder.php +++ /dev/null @@ -1,88 +0,0 @@ -uriFactory = new UriFactory(); - $this->requestFactory = new RequestFactory(); - $this->responseFactory = new ResponseFactory(); - $this->streamFactory = new StreamFactory(); - } - - public function buildClient(?BuzzClientInterface $client = null, array $options = []): Browser - { - return new Browser( - \is_null($client) ? new MultiCurl($this->responseFactory, $options) : $client, - $this->requestFactory, - ); - } - - public function getUriFactory(): UriFactoryInterface - { - return $this->uriFactory; - } - - public function setUriFactory(UriFactoryInterface $uriFactory): void - { - $this->uriFactory = $uriFactory; - } - - public function getRequestFactory(): RequestFactoryInterface - { - return $this->requestFactory; - } - - public function setRequestFactory(RequestFactoryInterface $requestFactory): void - { - $this->requestFactory = $requestFactory; - } - - public function getResponseFactory(): ResponseFactoryInterface - { - return $this->responseFactory; - } - - public function setResponseFactory(ResponseFactoryInterface $responseFactory): void - { - $this->responseFactory = $responseFactory; - } - - public function getStreamFactory(): StreamFactoryInterface - { - return $this->streamFactory; - } - - public function setStreamFactory(StreamFactoryInterface $streamFactory): void - { - $this->streamFactory = $streamFactory; - } -}