From 37e4204a91384eaa392d937ddd7a54c98dd9f44c Mon Sep 17 00:00:00 2001 From: sebprt Date: Fri, 20 Oct 2023 16:04:07 +0200 Subject: [PATCH 1/3] Added the reason in the message publish to RabbitMQ --- src/Rejection.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Rejection.php b/src/Rejection.php index 7305c59..579eb29 100644 --- a/src/Rejection.php +++ b/src/Rejection.php @@ -7,9 +7,9 @@ use Bunny\Channel; use Bunny\Client; use Kiboko\Contract\Pipeline\RejectionInterface; -use Kiboko\Contract\Pipeline\StepCodeInterface; +use Kiboko\Contract\Pipeline\RejectionWithReasonInterface; -final readonly class Rejection implements RejectionInterface +final readonly class Rejection implements RejectionInterface, RejectionWithReasonInterface { private Channel $channel; @@ -29,12 +29,6 @@ public function __construct( ); } - public function teardown(): void - { - $this->channel->close(); - $this->connection->stop(); - } - public static function withoutAuthentication( string $stepUuid, string $host, @@ -77,10 +71,10 @@ public static function withAuthentication( return new self($connection, stepUuid: $stepUuid, topic: $topic, exchange: $exchange); } - public function reject(StepCodeInterface $step, array|object $rejection, ?\Throwable $exception = null): void + public function reject(object|array $rejection, ?\Throwable $exception = null): void { $this->channel->publish( - \json_encode([ + json_encode([ 'item' => $rejection, 'exception' => $exception, 'step' => $this->stepUuid, @@ -93,11 +87,12 @@ public function reject(StepCodeInterface $step, array|object $rejection, ?\Throw ); } - public function rejectWithReason(StepCodeInterface $step, array|object $rejection, string $reason, ?\Throwable $exception = null): void + public function rejectWithReason(object|array $rejection, string $reason, ?\Throwable $exception = null): void { $this->channel->publish( - \json_encode([ + json_encode([ 'item' => $rejection, + 'reason' => $reason, 'exception' => $exception, 'step' => $this->stepUuid, ], \JSON_THROW_ON_ERROR), @@ -119,4 +114,10 @@ public function initialize(): void autoDelete: true, ); } + + public function teardown(): void + { + $this->channel->close(); + $this->connection->stop(); + } } From acbc609e3e1fa645c6c060d40eaa73e93b7a77f3 Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 3 Jul 2024 15:26:23 +0200 Subject: [PATCH 2/3] Change interface used on the Rejection object --- src/Rejection.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Rejection.php b/src/Rejection.php index 579eb29..63488d6 100644 --- a/src/Rejection.php +++ b/src/Rejection.php @@ -6,10 +6,9 @@ use Bunny\Channel; use Bunny\Client; -use Kiboko\Contract\Pipeline\RejectionInterface; -use Kiboko\Contract\Pipeline\RejectionWithReasonInterface; +use Kiboko\Contract\Pipeline\StepRejectionInterface; -final readonly class Rejection implements RejectionInterface, RejectionWithReasonInterface +final readonly class Rejection implements StepRejectionInterface { private Channel $channel; From 78207c597a9dae142cb2d34ba8ea0908a49acf69 Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 3 Jul 2024 16:11:24 +0200 Subject: [PATCH 3/3] Ran php-cs-fixer --- src/Rejection.php | 4 ++-- src/State.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Rejection.php b/src/Rejection.php index 63488d6..6141f8d 100644 --- a/src/Rejection.php +++ b/src/Rejection.php @@ -73,7 +73,7 @@ public static function withAuthentication( public function reject(object|array $rejection, ?\Throwable $exception = null): void { $this->channel->publish( - json_encode([ + \json_encode([ 'item' => $rejection, 'exception' => $exception, 'step' => $this->stepUuid, @@ -89,7 +89,7 @@ public function reject(object|array $rejection, ?\Throwable $exception = null): public function rejectWithReason(object|array $rejection, string $reason, ?\Throwable $exception = null): void { $this->channel->publish( - json_encode([ + \json_encode([ 'item' => $rejection, 'reason' => $reason, 'exception' => $exception, diff --git a/src/State.php b/src/State.php index 04103c8..e120020 100644 --- a/src/State.php +++ b/src/State.php @@ -16,7 +16,8 @@ public function __construct( private readonly StateManager $manager, private readonly string $stepCode, private readonly string $stepLabel, - ) {} + ) { + } public function accept(int $count = 1): void {