From 8f33d2bc91fd86c78f8e51aaeda767e6073e5c17 Mon Sep 17 00:00:00 2001 From: Marco Boers Date: Fri, 9 Aug 2024 11:41:08 +0200 Subject: [PATCH 1/2] Add recursively converting an element into values --- src/Traits/HasContent.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Traits/HasContent.php b/src/Traits/HasContent.php index 9bf6664..d53f7e5 100644 --- a/src/Traits/HasContent.php +++ b/src/Traits/HasContent.php @@ -32,4 +32,22 @@ public function getContent(): mixed { return $this->content; } + + /** + * Recursively convert element into values + */ + public function values(): array|string + { + $content = $this->getContent(); + + if (is_array($content)) { + foreach ($content as $key => $value) { + if ($value instanceof Element) { + $content[$key] = $value->values(); + } + } + } + + return $content; + } } From 99450da1f44161c64a25040730422a67a093165a Mon Sep 17 00:00:00 2001 From: Marco Boers Date: Fri, 9 Aug 2024 13:31:03 +0200 Subject: [PATCH 2/2] Import Element namespace --- src/Traits/HasContent.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Traits/HasContent.php b/src/Traits/HasContent.php index d53f7e5..bf4b446 100644 --- a/src/Traits/HasContent.php +++ b/src/Traits/HasContent.php @@ -4,6 +4,8 @@ namespace Saloon\XmlWrangler\Traits; +use Saloon\XmlWrangler\Data\Element; + trait HasContent { /**