From 0df43cb1432fb375b3ada0f2065db27aab4fc1c6 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 29 Aug 2024 19:58:24 -0500 Subject: [PATCH 1/2] setting xml loc to Element if type is a value container --- template/types/properties/methods/default.php | 18 ++++++++++++------ .../xml/primitive_xml_location_map.php | 2 +- .../types/serialization/xml/serialize/body.php | 10 +++++----- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/template/types/properties/methods/default.php b/template/types/properties/methods/default.php index ba736912..7085c1d9 100644 --- a/template/types/properties/methods/default.php +++ b/template/types/properties/methods/default.php @@ -66,16 +66,22 @@ public function get(): getFullyQualifiedName(true, PHPFHIR_ENUM_XML_LOCATION_ENUM); ?> $xmlLocation * @return static */ - public function getSetterName(); ?>( $ = null, $xmlLocation = ::ATTRIBUTE): self + public function getSetterName(); ?>( $ = null, $xmlLocation = ::isValueContainer()): ?>ELEMENTATTRIBUTE): self { if (null !== $ && !($ instanceof )) { $ = new ($); } $this->_trackValueAdded(Set($this->, $); - if (!isset($this->_primitiveXmlLocations[self::getFieldConstantName(); ?>])) { - $this->_primitiveXmlLocations[self::getFieldConstantName(); ?>] = []; + if (!isset($this->_xmlLocations[self::getFieldConstantName(); ?>])) { + $this->_xmlLocations[self::getFieldConstantName(); ?>] = []; } - $this->_primitiveXmlLocations[self::getFieldConstantName(); ?>][][0] = $xmlLocation; + if ([] === $this->_xmlLocations[self::getFieldConstantName(); ?>]) { + $this->_xmlLocations[self::getFieldConstantName(); ?>][0] = $xmlLocation; + } else { + $this->_xmlLocations[self::getFieldConstantName(); ?>][] = ::ELEMENT; + } +$this->_xmlLocations[self::getFieldConstantName(); ?>][0] = $xmlLocation; + $this-> = $; return $this; } @@ -91,9 +97,9 @@ public function getSetterName(); ?>(getFullyQualifiedName(true, PHPFHIR_ENUM_XML_LOCATION_ENUM); ?> $xmlLocation * @return static */ - public function set(array $ = [], $xmlLocation = ::ATTRIBUTE): self + public function set(array $ = [], $xmlLocation = ::isValueContainer()): ?>ELEMENTATTRIBUTE): self { - unset($this->_primitiveXmlLocations[self::getFieldConstantName(); ?>]); + unset($this->_xmlLocations[self::getFieldConstantName(); ?>]); if ([] !== $this->) { $this->_trackValuesRemoved(count($this->)); $this-> = []; diff --git a/template/types/serialization/xml/primitive_xml_location_map.php b/template/types/serialization/xml/primitive_xml_location_map.php index 5deb35e7..7ecbb53c 100644 --- a/template/types/serialization/xml/primitive_xml_location_map.php +++ b/template/types/serialization/xml/primitive_xml_location_map.php @@ -21,5 +21,5 @@ ob_start(); ?> /** @var array */ - private array $_primitiveXmlLocations = []; + private array $_xmlLocations = []; hasPrimitiveParent() || $pt->getKind()->isOneOf(TypeKind::PRIMITIVE, TypeKind::LIST)) : ?> - $locs = $this->_primitiveXmlLocations[self::getFieldConstantName(); ?>] ?? []; + $locs = $this->_xmlLocations[self::getFieldConstantName(); ?>] ?? []; isCollection()) : ?> if ([] === $locs && [] !== ($vs = $this->getGetterName(); ?>())) { $xw->writeAttribute(self::getFieldConstantName(); ?>, $vs[0]->getFormattedValue()); @@ -52,7 +52,7 @@ } getKind() === TypeKind::PRIMITIVE_CONTAINER) : ?> - $locs = $this->_primitiveXmlLocations[self::getFieldConstantName(); ?>] ?? []; + $locs = $this->_xmlLocations[self::getFieldConstantName(); ?>] ?? []; isCollection()) : ?> if ([] === $locs && [] !== ($vs = $this->getGetterName(); ?>())) { $xw->writeAttribute(self::getFieldConstantName(); ?>, $vs[0]->getValue()?->getFormattedValue()); @@ -99,7 +99,7 @@ } hasPrimitiveParent() || $ptk->isOneOf(TypeKind::LIST, TypeKind::PRIMITIVE)) : ?> - $locs = $this->_primitiveXmlLocations[self::getFieldConstantName(); ?>] ?? []; + $locs = $this->_xmlLocations[self::getFieldConstantName(); ?>] ?? []; isCollection()) : ?> if (([] === $locs || in_array(::ELEMENT, $locs, true)) && [] !== ($vs = $this->getGetterName(); ?>())) { foreach($vs as $i => $v) { @@ -118,7 +118,7 @@ } - $locs = $this->_primitiveXmlLocations[self::getFieldConstantName(); ?>] ?? []; + $locs = $this->_xmlLocations[self::getFieldConstantName(); ?>] ?? []; isCollection()) : ?> if (([] === $locs || in_array(::ELEMENT, $locs, true)) && [] !== ($vs = $this->getGetterName(); ?>())) { foreach($vs as $i => $v) { @@ -156,7 +156,7 @@ // // Uncomment and implement properly if the need arises in the future. /*?> - if (($this->_primitiveXmlLocations[self::FIELD_VALUE] ?? ::ATTRIBUTE) === ::ELEMENT) { + if (($this->_xmlLocations[self::FIELD_VALUE] ?? ::ATTRIBUTE) === ::ELEMENT) { $xw->writeSimpleElement(self::FIELD_VALUE, $this->getFormattedValue()); } Date: Thu, 29 Aug 2024 21:18:09 -0500 Subject: [PATCH 2/2] maybe one day I'll write a better test --- template/types/tests/unit/class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/template/types/tests/unit/class.php b/template/types/tests/unit/class.php index f60ceff6..73535aca 100644 --- a/template/types/tests/unit/class.php +++ b/template/types/tests/unit/class.php @@ -43,7 +43,7 @@ ] ); -if ($typeKind === TypeKind::PRIMITIVE) : +if ($typeKind === TypeKind::PRIMITIVE) { echo require_with( PHPFHIR_TEMPLATE_TYPE_TESTS_DIR . DIRECTORY_SEPARATOR . $testType->value . DIRECTORY_SEPARATOR . 'body_primitive.php', [ @@ -51,7 +51,7 @@ 'type' => $type, ] ); -endif; +} echo "}\n"; return ob_get_clean();