diff --git a/src/Utilities/ImportUtils.php b/src/Utilities/ImportUtils.php index 4ea47790..fb99d63c 100644 --- a/src/Utilities/ImportUtils.php +++ b/src/Utilities/ImportUtils.php @@ -187,9 +187,11 @@ public static function buildVersionTypeImports(Version $version, Type $type): vo $imports->addVersionCoreFileImportsByName($type->getVersion(), PHPFHIR_VERSION_CLASSNAME_VERSION_TYPE_MAP); $imports->addVersionCoreFileImportsByName($type->getVersion(), PHPFHIR_VERSION_CLASSNAME_VERSION); } else { - $valProp = $propertyType->isValueContainer() - ? $propertyType->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME) - : $propertyType->getParentProperty(PHPFHIR_VALUE_PROPERTY_NAME); + $valProp = match(true) { + $propertyType->isPrimitiveContainer() || $propertyType->isValueContainer() => $propertyType->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME), + $propertyType->hasPrimitiveContainerParent() || $propertyType->hasValueContainerParent() => $propertyType->getParentProperty(PHPFHIR_VALUE_PROPERTY_NAME), + default => null, + }; if (null !== $valProp) { $valType = $valProp->getValueFHIRType(); diff --git a/src/Utilities/TypeHintUtils.php b/src/Utilities/TypeHintUtils.php index ef1a1da4..7ea4a782 100644 --- a/src/Utilities/TypeHintUtils.php +++ b/src/Utilities/TypeHintUtils.php @@ -126,8 +126,12 @@ public static function buildBaseHintParts(Version $version, Type $type, bool $fu if ($type->isPrimitiveOrListType() || $type->hasPrimitiveOrListParent()) { $hintTypes = $type->getPrimitiveType()->getPHPReceiveValueTypeHints(); - } else if ($type->isValueContainer() || $type->hasValueContainerParent()) { - $valProp = $type->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME) ?? $type->getParentProperty(PHPFHIR_VALUE_PROPERTY_NAME); + } else if ($type->isValueContainer() || $type->hasValueContainerParent() || $type->isPrimitiveContainer() || $type->hasPrimitiveContainerParent()) { + $valProp = match (true) { + $type->isValueContainer() || $type->isPrimitiveContainer() => $type->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME), + $type->hasValueContainerParent() || $type->hasPrimitiveContainerParent() => $type->getParentProperty(PHPFHIR_VALUE_PROPERTY_NAME), + default => null, + }; $ptp = $valProp->getValueFHIRType(); $hintTypes = []; if ($ptp->isPrimitiveOrListType() || $ptp->hasPrimitiveOrListParent()) { @@ -264,8 +268,7 @@ public static function buildSetterParameterDocHint(Version $version, $hintTypes = self::buildBaseHintParts($version, $pt, true); - - if ($pt->isValueContainer() || $pt->hasValueContainerParent()) { + if ($pt->isValueContainer() || $pt->hasValueContainerParent() || $pt->isPrimitiveContainer() || $pt->hasPrimitiveContainerParent()) { $vp = $pt->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME) ?? $pt->getParentProperty(PHPFHIR_VALUE_PROPERTY_NAME); array_push( $hintTypes, @@ -311,7 +314,7 @@ public static function buildSetterParameterHint(Version $version, } else { $hintTypes = self::buildBaseHintParts($version, $pt, false); - if ($pt->isValueContainer() || $pt->hasValueContainerParent()) { + if ($pt->isValueContainer() || $pt->hasValueContainerParent() || $pt->isPrimitiveContainer() || $pt->hasPrimitiveContainerParent()) { $vp = $pt->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME) ?? $pt->getParentProperty(PHPFHIR_VALUE_PROPERTY_NAME); array_push( $hintTypes, diff --git a/src/Utils/XMLValueLocationUtils.php b/src/Utilities/XMLValueLocationUtils.php similarity index 83% rename from src/Utils/XMLValueLocationUtils.php rename to src/Utilities/XMLValueLocationUtils.php index 4dbecb55..9a198a25 100644 --- a/src/Utils/XMLValueLocationUtils.php +++ b/src/Utilities/XMLValueLocationUtils.php @@ -1,6 +1,6 @@ isValueProperty()) { $case = match (true) { - $type->isQuantity() || $type->hasQuantityParent() => 'CONTAINER_ATTRIBUTE', - $type->isValueContainer() || $type->hasValueContainerParent() => 'CONTAINER_ATTRIBUTE', + $type->isPrimitiveContainer() || $type->hasPrimitiveContainerParent() => 'CONTAINER_ATTRIBUTE', default => 'ELEMENT_ATTRIBUTE' }; } else { $case = match (true) { - $propType->isValueContainer() || $propType->hasValueContainerParent() => 'CONTAINER_ATTRIBUTE', + $propType->isPrimitiveContainer() || $propType->hasPrimitiveContainerParent() => 'CONTAINER_ATTRIBUTE', default => 'ELEMENT_ATTRIBUTE', }; } diff --git a/src/Version/Definition/Property.php b/src/Version/Definition/Property.php index 8a914d9c..b946ce4a 100644 --- a/src/Version/Definition/Property.php +++ b/src/Version/Definition/Property.php @@ -512,8 +512,8 @@ public function isSerializableAsXMLAttribute(): bool } return $propType->hasPrimitiveOrListParent() || $propType->isPrimitiveOrListType() - || $propType->hasValueContainerParent() - || $propType->isValueContainer(); + || $propType->hasPrimitiveContainerParent() + || $propType->isPrimitiveContainer(); } /** diff --git a/src/Version/Definition/TypeDecorator.php b/src/Version/Definition/TypeDecorator.php index 2b6b1445..1e2660d8 100644 --- a/src/Version/Definition/TypeDecorator.php +++ b/src/Version/Definition/TypeDecorator.php @@ -371,8 +371,7 @@ public static function setContainedTypeFlag(Config $config, Version $version, Ty } /** - * Once parsing has been completed, we must do a final pass to identify types that are primitive containers by - * another name. + * Primitive containers are Element types that contain a "value" element that is, itself, a primitive. * * @param \DCarbone\PHPFHIR\Version $version * @param \DCarbone\PHPFHIR\Version\Definition\Types $types diff --git a/template/core/types/interface_primitive_container_type.php b/template/core/types/interface_primitive_container_type.php index a43d1e26..723f4d4a 100644 --- a/template/core/types/interface_primitive_container_type.php +++ b/template/core/types/interface_primitive_container_type.php @@ -23,7 +23,7 @@ $coreFiles = $config->getCoreFiles(); -$elementInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_TYPES_INTERFACE_ELEMENT_TYPE); +$valueContainerInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_TYPES_INTERFACE_VALUE_CONTAINER_TYPE); $serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG); $xmlWriterClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_XML_WRITER); $xmlValueLocationEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_ENUM_VALUE_XML_LOCATION); @@ -31,7 +31,7 @@ $imports = $coreFile->getimports(); $imports->addCoreFileImports( - $elementInterface, + $valueContainerInterface, $serializeConfigClass, $xmlWriterClass, $xmlValueLocationEnum, @@ -46,16 +46,9 @@ -interface getEntityName(); ?> extends getEntityName(); ?> +interface getEntityName(); ?> extends getEntityName(); ?> { - /** - * Must return the appropriate "formatted" stringified version of this type's contained primitive type's value - * - * @return string - */ - public function _getFormattedValue(): string; - /** * Must return true if this primitive container type has a field set other than "value". This is used during * serialization. diff --git a/template/core/types/interface_value_container_type.php b/template/core/types/interface_value_container_type.php index 896fa4ff..8c7dc00d 100644 --- a/template/core/types/interface_value_container_type.php +++ b/template/core/types/interface_value_container_type.php @@ -23,7 +23,7 @@ $coreFiles = $config->getCoreFiles(); -$primitiveContainerInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_TYPES_INTERFACE_PRIMITIVE_CONTAINER_TYPE); +$elementInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_TYPES_INTERFACE_ELEMENT_TYPE); $serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG); $xmlWriterClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_XML_WRITER); $xmlValueLocationEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_ENUM_VALUE_XML_LOCATION); @@ -31,7 +31,7 @@ $imports = $coreFile->getimports(); $imports->addCoreFileImports( - $primitiveContainerInterface, + $elementInterface, $serializeConfigClass, $xmlWriterClass, $xmlValueLocationEnum, @@ -47,13 +47,17 @@ /** - * This indicates an Element type that contains a "value" property, but must be serialized differently than - * a primitive container + * This indicates an Element type that contains a "value" property */ -interface getEntityName(); ?> extends getEntityName(); ?> +interface getEntityName(); ?> extends getEntityName(); ?> { - + /** + * Must return the appropriate "formatted" stringified version of this type's contained primitive type's value + * + * @return string + */ + public function _getFormattedValue(): string; } getValueFHIRType(); ?> public const getFieldConstantName(); ?> = 'getName(); ?>'; -isPrimitiveContainer() || $propertyType->isValueContainer())) : +isPrimitiveContainer() || $propertyType->hasPrimitiveContainerParent())) : ?> public const getFieldConstantName(); ?>_EXT = 'getExtName(); ?>'; isValueContainer() || $type->hasValueContainerParent()) : ?> +if ($type->isPrimitiveContainer() || $type->hasPrimitiveContainerParent()) : ?> /* */ public function _nonValueFieldDefined(): bool diff --git a/template/versions/types/properties/methods/default.php b/template/versions/types/properties/methods/default.php index 76bca50d..0f7e4a75 100644 --- a/template/versions/types/properties/methods/default.php +++ b/template/versions/types/properties/methods/default.php @@ -17,7 +17,7 @@ */ use DCarbone\PHPFHIR\Enum\TypeKindEnum; -use DCarbone\PHPFHIR\Utils\XMLValueLocationUtils; +use DCarbone\PHPFHIR\Utilities\XMLValueLocationUtils; use DCarbone\PHPFHIR\Utilities\DocumentationUtils; use DCarbone\PHPFHIR\Utilities\TypeHintUtils; @@ -120,7 +120,9 @@ public function getSetterName(); ?>(isValueContainer() || $propType->hasValueContainerParent() || $propType->isPrimitiveOrListType() || $propType->hasPrimitiveOrListParent()) : ?> + if ($propType->isPrimitiveOrListType() || $propType->hasPrimitiveOrListParent() + || $propType->isPrimitiveContainer() || $propType->hasPrimitiveContainerParent() + || $propType->isValueContainer() || $propType->hasValueContainerParent()) : ?> if (!($ instanceof )) { $ = new (value: $); } @@ -173,7 +175,7 @@ public function set(isValueContainer()) : ?> + if ($propType->isPrimitiveContainer() || $propType->hasPrimitiveContainerParent()) : ?> $this-> = []; foreach($ as $v) { if ($v instanceof ) { @@ -217,28 +219,28 @@ public function _getValueXMLLocation() : ValueXMLLocation(getEntityName(); ?> $valueXMLLocation) : self { -isPrimitiveContainer() || $type->hasPrimitiveContainerParent()) : ?> +isPrimitiveContainer() || $type->hasPrimitiveContainerParent()) : ?> if (getEntityName(); ?>::PARENT_ATTRIBUTE === $valueXMLLocation) { throw new \InvalidArgumentException(sprintf( 'Cannot set "%s" as value XML serialize location for property "" on value container type "getFHIRName(); ?>"', $valueXMLLocation->name, )); } -isPrimitiveOrListType() || $propType->hasprimitiveType()) : ?> +isPrimitiveOrListType() || $propType->hasprimitiveType()) : ?> if (getEntityName(); ?>::CONTAINER_ATTRIBUTE === $valueXMLLocation) { throw new \InvalidArgumentException(sprintf( 'Cannot set "%s" as value XML serialize location for primitive property "" on type "getfhirName(); ?>"', $valueXMLLocation->name, )); } - + $this->_valueXMLLocations[self::getFieldConstantName(); ?>] = $valueXMLLocation; return $this; } isValueContainer() && !$type->hasValueContainerParent()) || ($type->isQuantity() && !$type->hasQuantityParent())): +if (($type->isPrimitiveContainer() && !$type->hasPrimitiveContainerParent()) || ($type->isValueContainer() && !$type->hasValueContainerParent())): $valueProp = $type->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME); ?> diff --git a/template/versions/types/serialization/xml/serialize/body.php b/template/versions/types/serialization/xml/serialize/body.php index e54a8a3e..bb370159 100644 --- a/template/versions/types/serialization/xml/serialize/body.php +++ b/template/versions/types/serialization/xml/serialize/body.php @@ -36,7 +36,7 @@ $propType = $property->getValueFHIRType(); if ($property->isValueProperty()) : - if ($type->isValueContainer() || $type->hasValueContainerParent()) : ?> + if ($type->isPrimitiveContainer() || $type->hasPrimitiveContainerParent()) : ?> if (isset($this->getName(); ?>) && getEntityName(); ?>::CONTAINER_ATTRIBUTE === $valueLocation) { $xw->writeAttribute(self::getFieldConstantName(); ?>, $this->getName(); ?>->_getFormattedValue()); } @@ -46,7 +46,7 @@ $xw->writeAttribute(self::getFieldConstantName(); ?>, $this->getName(); ?>->_getFormattedValue()); } isValueContainer() || $propType->hasValueContainerParent() || $propType->isPrimitiveOrListType() || $propType->hasPrimitiveOrListParent()) : ?> + elseif ($propType->isPrimitiveContainer() || $propType->hasPrimitiveContainerParent() || $propType->isPrimitiveOrListType() || $propType->hasPrimitiveOrListParent()) : ?> if (isset($this->getName(); ?>) && getEntityName(); ?>::PARENT_ATTRIBUTE === $this->_valueXMLLocations[self::getFieldConstantName(); ?>]) { $xw->writeAttribute(self::getFieldConstantName(); ?>, $this->getName(); ?>->_getFormattedValue()); } @@ -74,7 +74,7 @@ $propTypeKind = $propType->getKind(); // value property start - if (!$property->isCollection() && $property->isValueProperty() && ($type->isValueContainer() || $type->hasValueContainerParent())) : ?> + if (!$property->isCollection() && $property->isValueProperty() && ($type->isPrimitiveContainer() || $type->hasPrimitiveContainerParent())) : ?> if (isset($this->getName(); ?>)) { if (getEntityName(); ?>::CONTAINER_VALUE === $valueLocation) { $xw->text($this->getName(); ?>->_getFormattedValue()); @@ -136,7 +136,7 @@ // primitive type end // value container start - elseif ($propType->isValueContainer() || $propType->hasValueContainerParent()) : + elseif ($propType->isPrimitiveContainer() || $propType->hasPrimitiveContainerParent()) : if ($property->isCollection()) : ?> if (isset($this->getName(); ?>) && [] !== $this->getName(); ?>) { foreach($this->getName(); ?> as $v) {