Skip to content

Commit

Permalink
more xml fussing
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Jan 31, 2025
1 parent 6c3f762 commit fae0a6b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace DCarbone\PHPFHIR\Enum;
namespace DCarbone\PHPFHIR\Utils;

/*
* Copyright 2025 Daniel Carbone ([email protected])
Expand All @@ -26,18 +26,23 @@ class XMLValueLocationUtils
public static function determineDefaultLocation(Type $type, Property $property, bool $withClass): string
{
$propType = $property->getValueFHIRType();
if ($propType->isPrimitiveOrListType() || $propType->hasPrimitiveContainerParent()) {
$case = match(true) {
if ($property->isValueProperty()) {
$case = match (true) {
$type->isQuantity() || $type->hasQuantityParent() => 'CONTAINER_VALUE',
$type->isValueContainer() || $type->hasValueContainerParent() => 'CONTAINER_ATTRIBUTE',
default => 'ELEMENT_ATTRIBUTE'
};
} else if ($propType->isPrimitiveOrListType() || $propType->hasPrimitiveOrListParent()) {
$case = match (true) {
$type->isPrimitiveContainer() || $type->hasPrimitiveContainerParent() => 'CONTAINER_ATTRIBUTE',
default => 'ELEMENT_ATTRIBUTE',
};
} else if ($property->isValueProperty()) {
} else {
$case = match (true) {
$type->isQuantity() || $type->hasQuantityParent() => 'ELEMENT_ATTRIBUTE',
default => 'CONTAINER_ATTRIBUTE',
$type->isQuantity() || $type->hasQuantityParent() => 'CONTAINER_VALUE',
$propType->isValueContainer() || $propType->hasValueContainerParent() => 'CONTAINER_ATTRIBUTE',
default => 'ELEMENT_ATTRIBUTE',
};
} else {
$case = 'ELEMENT_ATTRIBUTE';
}
if ($withClass) {
return sprintf('%s::%s', PHPFHIR_ENCODING_ENUM_VALUE_XML_LOCATION, $case);
Expand Down
1 change: 1 addition & 0 deletions template/core/encoding/enum_value_xml_location.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum <?php echo PHPFHIR_ENCODING_ENUM_VALUE_XML_LOCATION; ?>
{
case PARENT_ATTRIBUTE;
case CONTAINER_ATTRIBUTE;
case CONTAINER_VALUE;
case ELEMENT_ATTRIBUTE;
case ELEMENT_VALUE;
}
Expand Down
2 changes: 1 addition & 1 deletion template/versions/types/class_default.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

use DCarbone\PHPFHIR\Enum\TypeKindEnum;
use DCarbone\PHPFHIR\Enum\XMLValueLocationUtils;
use DCarbone\PHPFHIR\Utils\XMLValueLocationUtils;
use DCarbone\PHPFHIR\Utilities\DocumentationUtils;
use DCarbone\PHPFHIR\Utilities\TypeHintUtils;

Expand Down
2 changes: 1 addition & 1 deletion template/versions/types/properties/methods/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

use DCarbone\PHPFHIR\Enum\TypeKindEnum;
use DCarbone\PHPFHIR\Enum\XMLValueLocationUtils;
use DCarbone\PHPFHIR\Utils\XMLValueLocationUtils;
use DCarbone\PHPFHIR\Utilities\DocumentationUtils;
use DCarbone\PHPFHIR\Utilities\TypeHintUtils;

Expand Down
8 changes: 5 additions & 3 deletions template/versions/types/serialization/xml/serialize/body.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@
// value property start
if (!$property->isCollection() && $property->isValueProperty() && ($type->isValueContainer() || $type->hasValueContainerParent())) : ?>
if (isset($this-><?php echo $property->getName(); ?>)) {
if (<?php echo $xmlLocationEnum->getEntityName(); ?>::ELEMENT_ATTRIBUTE === $valueLocation) {
if (<?php echo $xmlLocationEnum->getEntityName(); ?>::CONTAINER_VALUE === $valueLocation) {
$xw->text($this-><?php echo $property->getName(); ?>->_getFormattedValue());
} else if (<?php echo $xmlLocationEnum->getEntityName(); ?>::ELEMENT_ATTRIBUTE === $valueLocation) {
$xw->startElement(self::<?php echo $property->getFieldConstantName(); ?>);
$xw->writeAttribute(<?php echo $propType->getClassName(); ?>::<?php echo $property->getFieldConstantName(); ?>, $this-><?php echo $property->getName(); ?>->_getFormattedValue());
$xw->endElement();
Expand Down Expand Up @@ -133,7 +135,7 @@
<?php endif;
// primitive type end

// primitive container start
// value container start
elseif ($propType->isValueContainer() || $propType->hasValueContainerParent()) :
if ($property->isCollection()) : ?>
if (isset($this-><?php echo $property->getName(); ?>) && [] !== $this-><?php echo $property->getName(); ?>) {
Expand All @@ -152,7 +154,7 @@
$xw->endElement();
}
<?php endif;
// primitive container end
// value container end

// xhtml type start
elseif ($propTypeKind === TypeKindEnum::PHPFHIR_XHTML) : ?>
Expand Down

0 comments on commit fae0a6b

Please sign in to comment.