From 650c7067132c5b6e9037f05c158898231673e8fa Mon Sep 17 00:00:00 2001 From: Chernyy Aleksei Date: Wed, 21 Sep 2022 19:51:14 +0300 Subject: [PATCH 1/2] support the same tags on level --- src/Parsers/XMLParser.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Parsers/XMLParser.php b/src/Parsers/XMLParser.php index f879642..c16332c 100644 --- a/src/Parsers/XMLParser.php +++ b/src/Parsers/XMLParser.php @@ -60,7 +60,7 @@ private function searchElement(callable $function) private function extractElement(String $elementName, $couldBeAnElementsList = false, int $parentDepth, string $foundInEl = null) { $emptyElement = $this->isEmptyElement($elementName); - + $elementCollection = new Collection(); $elementParameters = $this->getCurrentElementAttributes(); @@ -94,8 +94,19 @@ private function extractElement(String $elementName, $couldBeAnElementsList = fa $foundElementName = $this->reader->name; $elementCollection->push(new Collection($this->extractElement($foundElementName, false, $this->reader->depth, $elementName))); } else { - $foundElementName = $this->reader->name; - $elementCollection->put($foundElementName, $this->extractElement($foundElementName, true, $this->reader->depth)); + $foundElementName = $this->reader->name; + $value = $this->extractElement($foundElementName, true, $this->reader->depth); + + if ($elementCollection->has($foundElementName)) { + $existantValue = $elementCollection->get($foundElementName); + if (is_string($existantValue)) { + $existantValue = collect([$existantValue]); + $elementCollection->put($foundElementName, $existantValue); + } + $elementCollection->put($foundElementName, $existantValue->merge([$value])); + } else { + $elementCollection->put($foundElementName, $value); + } } } } From 925c97a0e0950d182526eacf8987c0e5350cd824 Mon Sep 17 00:00:00 2001 From: aleksei4er <63870560+aleksei4er@users.noreply.github.com> Date: Fri, 4 Aug 2023 18:39:43 +0300 Subject: [PATCH 2/2] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 059ee43..c3da0c1 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "require": { "php": ">=7.1", "ext-xmlreader": "*", - "maxakawizard/json-collection-parser": "^1.1", + "maxakawizard/json-collection-parser": "^1.9", "tightenco/collect": "^5.0|^6.0|^7.0|^8.0" },