From 66d3159575595a710b89dcbc1f67295d5e9e2e03 Mon Sep 17 00:00:00 2001 From: natepage Date: Tue, 9 Mar 2021 22:49:29 +1100 Subject: [PATCH] [EasyWebhook] Implement rewind on stack to allow calling the same instance of webhook client more than once --- packages/EasyWebhook/src/Interfaces/StackInterface.php | 2 ++ packages/EasyWebhook/src/Stack.php | 5 +++++ packages/EasyWebhook/src/WebhookClient.php | 3 +++ 3 files changed, 10 insertions(+) diff --git a/packages/EasyWebhook/src/Interfaces/StackInterface.php b/packages/EasyWebhook/src/Interfaces/StackInterface.php index bf3e2beeb7..ebd3d95d8e 100644 --- a/packages/EasyWebhook/src/Interfaces/StackInterface.php +++ b/packages/EasyWebhook/src/Interfaces/StackInterface.php @@ -7,4 +7,6 @@ interface StackInterface { public function next(): MiddlewareInterface; + + public function rewind(): void; } diff --git a/packages/EasyWebhook/src/Stack.php b/packages/EasyWebhook/src/Stack.php index cd0e2b87d0..f8b61596f8 100644 --- a/packages/EasyWebhook/src/Stack.php +++ b/packages/EasyWebhook/src/Stack.php @@ -52,4 +52,9 @@ public function next(): MiddlewareInterface return $next; } + + public function rewind(): void + { + $this->index = 0; + } } diff --git a/packages/EasyWebhook/src/WebhookClient.php b/packages/EasyWebhook/src/WebhookClient.php index ba0c4e5c17..f3f90e2282 100644 --- a/packages/EasyWebhook/src/WebhookClient.php +++ b/packages/EasyWebhook/src/WebhookClient.php @@ -28,6 +28,9 @@ public function getStack(): StackInterface public function sendWebhook(WebhookInterface $webhook): WebhookResultInterface { + // Make sure stack is "fresh" + $this->stack->rewind(); + return $this->stack ->next() ->process($webhook, $this->stack);