diff --git a/app/Check/Consumers/Client/ClientBuilder.php b/app/Check/Consumers/Client/ClientBuilder.php new file mode 100644 index 0000000..88a6a87 --- /dev/null +++ b/app/Check/Consumers/Client/ClientBuilder.php @@ -0,0 +1,104 @@ +connectTimeout = $connectTimeout; + $this->timeout = $timeout; + } + + + public function withVerify(bool $verify): self + { + $factory = clone $this; + $factory->verify = $verify; + + return $factory; + } + + + public function withAllowRedirects(\Pd\Monitoring\Check\Consumers\Client\Conf\AllowRedirectsInterface $allowRedirects): self + { + $factory = clone $this; + $factory->allowRedirects = $allowRedirects; + + return $factory; + } + + + public function withTimeout(int $timeout): self + { + $factory = clone $this; + $factory->timeout = $timeout; + + return $factory; + } + + + public function withConnectTimeout(int $defaultTimeout): self + { + $builder = clone $this; + $builder->connectTimeout = $defaultTimeout; + + return $builder; + } + + + public static function create( + int $connectTimeout, + int $timeout + ): self + { + return new self($connectTimeout, $timeout); + } + + + /** + * @return array> + */ + private function config(): array + { + $config = [ + 'verify' => $this->verify, + 'connect_timeout' => $this->connectTimeout, + 'timeout' => $this->timeout, + ]; + + $headers = [ + 'headers' => [ + 'User-Agent' => 'PeckaMonitoringBot/1.0', + ], + ]; + + return \array_filter( + \array_merge( + $config, + $headers, + $this->allowRedirects->toArray() + ) + ); + } + + + public function build(): \GuzzleHttp\Client + { + return new \GuzzleHttp\Client($this->config()); + } + +} diff --git a/app/Check/Consumers/Client/Conf/AllowRedirects.php b/app/Check/Consumers/Client/Conf/AllowRedirects.php new file mode 100644 index 0000000..25db78e --- /dev/null +++ b/app/Check/Consumers/Client/Conf/AllowRedirects.php @@ -0,0 +1,29 @@ +isAllowed = $isAllowed; + } + + public function toArray(): array + { + return [ + AllowRedirectsInterface::ALLOW_REDIRECTS => $this->isAllowed, + ]; + } + + + public static function create(bool $isAllowed): self + { + return new self($isAllowed); + } + +} diff --git a/app/Check/Consumers/Client/Conf/AllowRedirectsArray.php b/app/Check/Consumers/Client/Conf/AllowRedirectsArray.php new file mode 100644 index 0000000..22baa54 --- /dev/null +++ b/app/Check/Consumers/Client/Conf/AllowRedirectsArray.php @@ -0,0 +1,26 @@ + + */ + private array $conf; + + + public function __construct(array $conf) + { + $this->conf = $conf; + } + + public function toArray(): array + { + return [ + AllowRedirectsInterface::ALLOW_REDIRECTS => $this->conf, + ]; + } + +} diff --git a/app/Check/Consumers/Client/Conf/AllowRedirectsInterface.php b/app/Check/Consumers/Client/Conf/AllowRedirectsInterface.php new file mode 100644 index 0000000..38b33b3 --- /dev/null +++ b/app/Check/Consumers/Client/Conf/AllowRedirectsInterface.php @@ -0,0 +1,12 @@ +