From 6a95147a6ffdb8cedc8e38e87fc4c48b20e25378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Planchat?= Date: Wed, 15 Nov 2023 11:23:15 +0100 Subject: [PATCH] Moved the ActionState class from the php-etl/action-contracts package --- src/ActionState.php | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/ActionState.php diff --git a/src/ActionState.php b/src/ActionState.php new file mode 100644 index 0000000..059d3a0 --- /dev/null +++ b/src/ActionState.php @@ -0,0 +1,55 @@ + */ + private array $metrics = [ + 'started' => false, + 'success' => false, + 'failure' => false, + ]; + + public function __construct( + private readonly StateInterface $decorated, + ) { + } + + public function initialize(): void + { + $this->metrics['started'] = true; + $this->decorated->initialize(); + } + + public function success(): void + { + $this->metrics['success'] = true; + $this->decorated->success(); + } + + public function failure(int $step = 1): void + { + $this->metrics['failure'] = true; + $this->decorated->failure(); + } + + public function observeAccept(): callable + { + return fn () => $this->metrics['success']; + } + + public function observeReject(): callable + { + return fn () => $this->metrics['failure']; + } + + public function teardown(): void + { + $this->decorated->teardown(); + } +}