From 6cd0a9558ab25a752840883eccc9798ec58f1943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Quang=20Tr=C6=B0=E1=BB=9Dng?= Date: Thu, 5 Jan 2023 13:13:09 +0700 Subject: [PATCH] update add retry logic with only logic --- src/Servers/Client.php | 4 ++-- src/Servers/Host.php | 14 +++++++------- src/Servers/HostInterface.php | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Servers/Client.php b/src/Servers/Client.php index eb954df..b8db10e 100644 --- a/src/Servers/Client.php +++ b/src/Servers/Client.php @@ -142,9 +142,9 @@ function ( try_time: $retries + 1 ); - foreach ($this->current_host->getRetriesLogic() as $retry_callable) { + if ($this->current_host->getRetryLogic() && is_callable($this->current_host->getRetryLogic())) { $result_call_func = call_user_func( - $retry_callable, + $this->current_host->getRetryLogic(), $this->current_host, $retries, $request, diff --git a/src/Servers/Host.php b/src/Servers/Host.php index c7128d6..925674e 100644 --- a/src/Servers/Host.php +++ b/src/Servers/Host.php @@ -8,9 +8,9 @@ final class Host implements HostInterface { /** - * @var array $retries_logic + * @var callable $retry_logic * */ - private array $retries_logic = []; + private $retry_logic = null; /** * Function constructor @@ -67,21 +67,21 @@ public function validateConstructor() */ public function addRetryLogic(callable $retry_logic): void { - if(!is_callable($retry_logic)){ + if (!is_callable($retry_logic)) { throw new InvalidCallableException(); } - $this->retries_logic[] = $retry_logic; + $this->retry_logic = $retry_logic; } /** * Get retry logic * - * @return array + * @return callable|null * */ - public function getRetriesLogic(): array + public function getRetryLogic(): callable|null { - return $this->retries_logic; + return $this->retry_logic; } /** diff --git a/src/Servers/HostInterface.php b/src/Servers/HostInterface.php index 64c8d15..f32f959 100644 --- a/src/Servers/HostInterface.php +++ b/src/Servers/HostInterface.php @@ -20,7 +20,7 @@ public function addRetryLogic(callable $retry_logic): void; /** * Get retry logic * - * @return array + * @return callable|null * */ - public function getRetriesLogic(): array; + public function getRetryLogic(): callable|null; }