From 61d6584fd5a9fdf9e41de0058805cca1fddd3405 Mon Sep 17 00:00:00 2001 From: arabcoders Date: Fri, 9 May 2025 22:47:52 +0300 Subject: [PATCH] Add removeMetadata to StateInterface. --- src/Libs/Entity/StateEntity.php | 16 ++++++++++++++++ src/Libs/Entity/StateInterface.php | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Libs/Entity/StateEntity.php b/src/Libs/Entity/StateEntity.php index 55cc8ab3..3d18df25 100644 --- a/src/Libs/Entity/StateEntity.php +++ b/src/Libs/Entity/StateEntity.php @@ -459,6 +459,22 @@ final class StateEntity implements iState return $this->metadata[$via] ?? []; } + /** + * @inheritdoc + */ + public function removeMetadata(string $backend): array + { + if (null === ($this->metadata[$backend] ?? null)) { + return []; + } + + $metadata = $this->metadata[$backend]; + + unset($this->metadata[$backend]); + + return $metadata; + } + /** * @inheritdoc */ diff --git a/src/Libs/Entity/StateInterface.php b/src/Libs/Entity/StateInterface.php index fbc51375..6b682f63 100644 --- a/src/Libs/Entity/StateInterface.php +++ b/src/Libs/Entity/StateInterface.php @@ -295,6 +295,15 @@ interface StateInterface extends LoggerAwareInterface */ public function getMetadata(string|null $via = null): array; + /** + * Get metadata. + * + * @param string $backend The backend name to remove metadata from. + * + * @return array Return the removed metadata. Or empty array if not found. + */ + public function removeMetadata(string $backend): array; + /** * Set metadata related to {$this->via} backend. *