From 2979ac3439c29350267a89d00a0779d2500d5021 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 23 Jan 2025 10:38:55 -0600 Subject: [PATCH] halfway fix for xhtml, v5 will require better templating and typing sytsem --- files/constants.php | 14 +-- src/Utilities/ImportUtils.php | 7 +- src/Utilities/TypeHintUtils.php | 27 +++--- src/Version/Definition/Type.php | 16 ++-- src/Version/Definition/Types.php | 2 - template/core/class_response_parser.php | 35 +++++--- .../interface_comment_container.php | 2 +- .../{ => types}/interface_contained_type.php | 4 +- .../{ => types}/interface_primitive_type.php | 2 +- template/core/{ => types}/interface_type.php | 6 +- .../{ => types}/trait_comment_container.php | 2 +- template/core/validation/class_validator.php | 20 ++--- .../versions/interface_version_type_map.php | 6 +- .../versions/core/class_version_client.php | 6 +- .../versions/core/class_version_type_map.php | 8 +- .../core/interface_version_contained_type.php | 4 +- template/versions/types/class_xhtml.php | 90 +++---------------- .../types/properties/methods/default.php | 5 ++ .../serialization/json/unserialize/body.php | 6 +- .../serialization/json/unserialize/header.php | 4 +- .../serialization/xml/serialize/body.php | 14 ++- .../serialization/xml/unserialize/body.php | 5 +- .../serialization/xml/unserialize/header.php | 2 +- 23 files changed, 136 insertions(+), 151 deletions(-) rename template/core/{ => types}/interface_comment_container.php (95%) rename template/core/{ => types}/interface_contained_type.php (87%) rename template/core/{ => types}/interface_primitive_type.php (96%) rename template/core/{ => types}/interface_type.php (96%) rename template/core/{ => types}/trait_comment_container.php (97%) diff --git a/files/constants.php b/files/constants.php index 6f2d5aac..eb6bc735 100644 --- a/files/constants.php +++ b/files/constants.php @@ -43,7 +43,6 @@ // raw type const PHPFHIR_XHTML_TYPE_NAME = 'XHTML'; -const PHPFHIR_XHTML_TYPE_DESCRIPTION = 'XHTML type used in special cases'; // FHIR XML NS const PHPFHIR_FHIR_XMLNS = 'https://hl7.org/fhir'; @@ -92,16 +91,11 @@ const PHPFHIR_CLASSNAME_VALIDATOR = 'Validator'; // Core interface names -const PHPFHIR_INTERFACE_TYPE = 'TypeInterface'; -const PHPFHIR_INTERFACE_CONTAINED_TYPE = 'ContainedTypeInterface'; -const PHPFHIR_INTERFACE_COMMENT_CONTAINER = 'CommentContainerInterface'; -const PHPFHIR_INTERFACE_PRIMITIVE_TYPE = 'PrimitiveTypeInterface'; const PHPFHIR_INTERFACE_VERSION = 'VersionInterface'; const PHPFHIR_INTERFACE_VERSION_CONFIG = 'VersionConfigInterface'; const PHPFHIR_INTERFACE_VERSION_TYPE_MAP = 'VersionTypeMapInterface'; // Core traits -const PHPFHIR_TRAIT_COMMENT_CONTAINER = 'CommentContainerTrait'; const PHPFHIR_TRAIT_SOURCE_XMLNS = 'SourceXMLNamespaceTrait'; // Core enums @@ -112,6 +106,14 @@ const PHPFHIR_EXCEPTION_CLIENT_ERROR = 'ClientErrorException'; const PHPFHIR_EXCEPTION_CLIENT_UNEXPECTED_RESPONSE_CODE = 'UnexpectedResponseCodeException'; +// Core types entities +const PHPFHIR_TYPES_INTERFACE_TYPE = 'TypeInterface'; +const PHPFHIR_TYPES_INTERFACE_CONTAINED_TYPE = 'ContainedTypeInterface'; +const PHPFHIR_TYPES_INTERFACE_COMMENT_CONTAINER = 'CommentContainerInterface'; +const PHPFHIR_TYPES_INTERFACE_PRIMITIVE_TYPE = 'PrimitiveTypeInterface'; +const PHPFHIR_TYPES_TRAIT_COMMENT_CONTAINER = 'CommentContainerTrait'; + + // Core encoding entities const PHPFHIR_ENCODING_CLASSNAME_XML_WRITER = 'XMLWriter'; const PHPFHIR_ENCODING_ENUM_VALUE_XML_LOCATION = 'ValueXMLLocationEnum'; diff --git a/src/Utilities/ImportUtils.php b/src/Utilities/ImportUtils.php index 6e8fd9bf..1b9b43d4 100644 --- a/src/Utilities/ImportUtils.php +++ b/src/Utilities/ImportUtils.php @@ -46,6 +46,11 @@ public static function buildVersionTypeImports(Version $version, Type $type): vo // immediately add self $imports->addImport($type->getFullyQualifiedNamespace(false), $type->getClassName()); + // xhtml type has too many special cases, do better. + if ($type->getFHIRName() === PHPFHIR_XHTML_TYPE_NAME) { + return; + } + $typeKind = $type->getKind(); if (!$type->isAbstract()) { @@ -54,7 +59,7 @@ public static function buildVersionTypeImports(Version $version, Type $type): vo PHPFHIR_ENCODING_ENUM_VALUE_XML_LOCATION, PHPFHIR_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG, PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG, - PHPFHIR_INTERFACE_TYPE, + PHPFHIR_TYPES_INTERFACE_TYPE, ); } diff --git a/src/Utilities/TypeHintUtils.php b/src/Utilities/TypeHintUtils.php index 34b22991..05f4d2da 100644 --- a/src/Utilities/TypeHintUtils.php +++ b/src/Utilities/TypeHintUtils.php @@ -124,15 +124,14 @@ public static function buildBaseHintParts(Version $version, Type $type, bool $fu // fetch type's kind $tk = $type->getKind(); - if ($tk->isOneOf(TypeKindEnum::PRIMITIVE, TypeKindEnum::LIST)) { + if ($type->isPrimitiveOrListType()) { $hintTypes = $type->getPrimitiveType()->getPHPReceiveValueTypeHints(); - } else if ($tk === TypeKindEnum::PRIMITIVE_CONTAINER) { + } else if ($type->isPrimitiveContainer()) { $ptp = $type->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME)->getValueFHIRType(); $hintTypes = $ptp->getPrimitiveType()->getPHPReceiveValueTypeHints(); array_merge($hintTypes, self::buildBaseHintParts($version, $ptp, $fullyQualified)); } else if ($tk->isResourceContainer($version)) { $containerType = $version->getDefinition()->getTypes()->getContainerType(); - $hintTypes = match ($fullyQualified) { true => [ $containerType->getFullyQualifiedClassName(true), @@ -143,6 +142,16 @@ public static function buildBaseHintParts(Version $version, Type $type, bool $fu PHPFHIR_VERSION_INTERFACE_VERSION_CONTAINED_TYPE, ], }; + } else if ($type->getKind() === TypeKindEnum::PHPFHIR_XHTML) { + $hintTypes = [ + 'string', + '\\SimpleXMLElement', + '\\DOMNode', + match ($fullyQualified) { + true => $type->getFullyQualifiedClassName(true), + false => $type->getClassName(), + }, + ]; } else { $hintTypes = [ match ($fullyQualified) { @@ -232,6 +241,7 @@ public static function propertyGetterDocHint(Version $version, * @param bool $nullable * @param bool $ignoreCollection * @return string + * @throws \Exception */ public static function buildSetterParameterDocHint(Version $version, Property $property, @@ -250,13 +260,12 @@ public static function buildSetterParameterDocHint(Version $version, $hintTypes = self::buildBaseHintParts($version, $pt, true); - $ptk = $pt->getKind(); - if ($property->isValueProperty() || $ptk->isOneOf(TypeKindEnum::LIST, TypeKindEnum::PRIMITIVE)) { + if ($property->isValueProperty() || $pt->isPrimitiveOrListType()) { $hintTypes[] = $pt->getFullyQualifiedClassName(true); } - if ($ptk === TypeKindEnum::PRIMITIVE_CONTAINER) { + if ($pt->isPrimitiveContainer()) { $vp = $pt->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME); array_push( $hintTypes, @@ -300,13 +309,11 @@ public static function buildSetterParameterHint(Version $version, } else { $hintTypes = self::buildBaseHintParts($version, $pt, false); - $ptk = $pt->getKind(); - - if ($property->isValueProperty() || $ptk->isOneOf(TypeKindEnum::LIST, TypeKindEnum::PRIMITIVE)) { + if ($property->isValueProperty() || $pt->isPrimitiveOrListType()) { $hintTypes[] = $pt->getClassName(); } - if ($ptk === TypeKindEnum::PRIMITIVE_CONTAINER) { + if ($pt->isPrimitiveContainer()) { $vp = $pt->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME); array_push( $hintTypes, diff --git a/src/Version/Definition/Type.php b/src/Version/Definition/Type.php index 0677c01f..0844f304 100644 --- a/src/Version/Definition/Type.php +++ b/src/Version/Definition/Type.php @@ -823,8 +823,8 @@ public function getDirectlyImplementedInterfaces(): array if (null === $parentType) { if ($this->isCommentContainer()) { - $interfaces[PHPFHIR_INTERFACE_COMMENT_CONTAINER] = $coreFiles - ->getCoreFileByEntityName(PHPFHIR_INTERFACE_COMMENT_CONTAINER) + $interfaces[PHPFHIR_TYPES_INTERFACE_COMMENT_CONTAINER] = $coreFiles + ->getCoreFileByEntityName(PHPFHIR_TYPES_INTERFACE_COMMENT_CONTAINER) ->getFullyQualifiedNamespace(false); } if ($this->isContainedType()) { @@ -832,12 +832,12 @@ public function getDirectlyImplementedInterfaces(): array ->getCoreFileByEntityName(PHPFHIR_VERSION_INTERFACE_VERSION_CONTAINED_TYPE) ->getFullyQualifiedNamespace(false); } else if ($this->getKind() === TypeKindEnum::PRIMITIVE) { - $interfaces[PHPFHIR_INTERFACE_PRIMITIVE_TYPE] = $coreFiles - ->getCoreFileByEntityName(PHPFHIR_INTERFACE_PRIMITIVE_TYPE) + $interfaces[PHPFHIR_TYPES_INTERFACE_PRIMITIVE_TYPE] = $coreFiles + ->getCoreFileByEntityName(PHPFHIR_TYPES_INTERFACE_PRIMITIVE_TYPE) ->getFullyQualifiedNamespace(false); } else { - $interfaces[PHPFHIR_INTERFACE_TYPE] = $coreFiles - ->getCoreFileByEntityName(PHPFHIR_INTERFACE_TYPE) + $interfaces[PHPFHIR_TYPES_INTERFACE_TYPE] = $coreFiles + ->getCoreFileByEntityName(PHPFHIR_TYPES_INTERFACE_TYPE) ->getFullyQualifiedNamespace(false); } } elseif ($this->isContainedType() && !$parentType->isContainedType()) { @@ -862,8 +862,8 @@ public function getDirectlyUsedTraits(): array // if this type has no parent(s), try to add all traits if ($this->isCommentContainer()) { - $traits[PHPFHIR_TRAIT_COMMENT_CONTAINER] = $coreFiles - ->getCoreFileByEntityName(PHPFHIR_TRAIT_COMMENT_CONTAINER) + $traits[PHPFHIR_TYPES_TRAIT_COMMENT_CONTAINER] = $coreFiles + ->getCoreFileByEntityName(PHPFHIR_TYPES_TRAIT_COMMENT_CONTAINER) ->getFullyQualifiedNamespace(false); } diff --git a/src/Version/Definition/Types.php b/src/Version/Definition/Types.php index 416c3731..5d5e9934 100644 --- a/src/Version/Definition/Types.php +++ b/src/Version/Definition/Types.php @@ -59,8 +59,6 @@ public function __construct(Version $version) // TODO(dcarbone): this sucks. $xt = new Type($version, PHPFHIR_XHTML_TYPE_NAME); $xt->setKind(TypeKindEnum::PHPFHIR_XHTML); - $xt->addDocumentationFragment(PHPFHIR_XHTML_TYPE_DESCRIPTION); - $this->addType($xt); } diff --git a/template/core/class_response_parser.php b/template/core/class_response_parser.php index 3da7d239..706ed951 100644 --- a/template/core/class_response_parser.php +++ b/template/core/class_response_parser.php @@ -16,13 +16,24 @@ * limitations under the License. */ +use DCarbone\PHPFHIR\Utilities\ImportUtils; + /** @var \DCarbone\PHPFHIR\Config $config */ /** @var \DCarbone\PHPFHIR\CoreFile $coreFile */ $coreFiles = $config->getCoreFiles(); $versionInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_VERSION); -$typeInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_TYPE); +$typeInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_TYPES_INTERFACE_TYPE); +$constantsClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_CONSTANTS); + +$imports = $coreFile->getImports(); + +$imports->addCoreFileImports( + $versionInterface, + $typeInterface, + $constantsClass, +); ob_start(); echo 'declare(strict_types=1); @@ -31,6 +42,8 @@ getBasePHPFHIRCopyrightComment(true); ?> + + class { @@ -47,7 +60,7 @@ class * @throws \Exception */ public static function parse( $version, - null|string|array|\stdClass|\SimpleXMLElement|\DOMDocument $input): null| + null|string|array|\stdClass|\SimpleXMLElement|\DOMDocument $input): null| { if (null === $input) { @@ -68,7 +81,7 @@ public static function parse( $version, */ public static function parseArray( $version, - array $input): null| + array $input): null| { if ([] === $input) { @@ -100,7 +113,7 @@ public static function parseArray( $vers */ public static function parseStdClass( $version, - \stdClass $input): null| + \stdClass $input): null| { return static::parseArray($version, (array)$input); @@ -113,11 +126,11 @@ public static function parseStdClass( $v */ public static function parseSimpleXMLElement( $version, - \SimpleXMLElement $input): null| + \SimpleXMLElement $input): null| { $elementName = $input->getName(); - /** @var getFullyQualifiedName(true, PHPFHIR_INTERFACE_TYPE); ?> $fhirType */ + /** @var getFullyQualifiedName(true, PHPFHIR_TYPES_INTERFACE_TYPE); ?> $fhirType */ $fhirType = $version->getTypeMap()::getTypeClassName($elementName); if (null === $fhirType) { throw new \UnexpectedValueException(sprintf( @@ -136,7 +149,7 @@ public static function parseSimpleXMLElement( $version, - \DOMDocument $input): null| + \DOMDocument $input): null| { return static::parseSimpleXMLElement($version, simplexml_import_dom($input)); @@ -149,7 +162,7 @@ public static function parseDOMDocument( */ public static function parseObject( $version, - \stdClass|\SimpleXMLElement|\DOMDocument $input): null| + \stdClass|\SimpleXMLElement|\DOMDocument $input): null| { if ($input instanceof \stdClass) { @@ -169,7 +182,7 @@ public static function parseObject( $ver * @throws \Exception */ public static function parseXML( $version, - string $input): null| + string $input): null| { return static::parseSimpleXMLElement( @@ -184,7 +197,7 @@ public static function parseXML( $versio */ public static function parseJSON( $version, - string $input): null| + string $input): null| { $decoded = json_decode($input, true, $version->getConfig()->getUnserializeConfig()->getJSONDecodeMaxDepth()); @@ -208,7 +221,7 @@ public static function parseJSON( $versi * @throws \Exception */ public static function parseString( $version, - string $input): null| + string $input): null| { $input = trim($input); diff --git a/template/core/interface_comment_container.php b/template/core/types/interface_comment_container.php similarity index 95% rename from template/core/interface_comment_container.php rename to template/core/types/interface_comment_container.php index 4891f6a4..cb2a142f 100644 --- a/template/core/interface_comment_container.php +++ b/template/core/types/interface_comment_container.php @@ -26,7 +26,7 @@ getBasePHPFHIRCopyrightComment(true); ?> -interface +interface { /** diff --git a/template/core/interface_contained_type.php b/template/core/types/interface_contained_type.php similarity index 87% rename from template/core/interface_contained_type.php rename to template/core/types/interface_contained_type.php index 412d5df5..3dee098a 100644 --- a/template/core/interface_contained_type.php +++ b/template/core/types/interface_contained_type.php @@ -27,13 +27,13 @@ getBasePHPFHIRCopyrightComment(true); ?> /** - * Interface + * Interface * * This is a meta interface that must never be directly implemented by a class. It exists purely to ensure type safety * throughout the base package. */ -interface extends +interface extends { /** diff --git a/template/core/interface_primitive_type.php b/template/core/types/interface_primitive_type.php similarity index 96% rename from template/core/interface_primitive_type.php rename to template/core/types/interface_primitive_type.php index 4ce15e89..99ec5e76 100644 --- a/template/core/interface_primitive_type.php +++ b/template/core/types/interface_primitive_type.php @@ -39,7 +39,7 @@ -interface extends \JsonSerializable +interface extends \JsonSerializable { /** * Returns the FHIR name represented by this Type diff --git a/template/core/interface_type.php b/template/core/types/interface_type.php similarity index 96% rename from template/core/interface_type.php rename to template/core/types/interface_type.php index c0b8dc1b..d95ab5f8 100644 --- a/template/core/interface_type.php +++ b/template/core/types/interface_type.php @@ -45,7 +45,7 @@ -interface extends \JsonSerializable +interface extends \JsonSerializable { /** * Returns the FHIR name represented by this Type @@ -84,7 +84,7 @@ public function _getValidationErrors(): array; * @return static */ public static function xmlUnserialize(string|\SimpleXMLElement $element, - null| $type = null, + null| $type = null, null| $config = null): self; /** @@ -103,7 +103,7 @@ public function xmlSerialize(null| $type = null, + null| $type = null, null| $config = null): self; /** diff --git a/template/core/trait_comment_container.php b/template/core/types/trait_comment_container.php similarity index 97% rename from template/core/trait_comment_container.php rename to template/core/types/trait_comment_container.php index 91c92eb4..338c2cb6 100644 --- a/template/core/trait_comment_container.php +++ b/template/core/types/trait_comment_container.php @@ -26,7 +26,7 @@ getBasePHPFHIRCopyrightComment(true); ?> -trait +trait { /** @var array */ diff --git a/template/core/validation/class_validator.php b/template/core/validation/class_validator.php index 127d3f4f..090b7de2 100644 --- a/template/core/validation/class_validator.php +++ b/template/core/validation/class_validator.php @@ -26,12 +26,12 @@ $imports->addCoreFileImportsByName( PHPFHIR_CLASSNAME_CONSTANTS, - PHPFHIR_INTERFACE_TYPE, - PHPFHIR_INTERFACE_PRIMITIVE_TYPE, + PHPFHIR_TYPES_INTERFACE_TYPE, + PHPFHIR_TYPES_INTERFACE_PRIMITIVE_TYPE, ); -$typeInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_TYPE); -$pimitiveTypeInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_PRIMITIVE_TYPE); +$typeInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_TYPES_INTERFACE_TYPE); +$pimitiveTypeInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_TYPES_INTERFACE_PRIMITIVE_TYPE); ob_start(); echo 'declare(strict_types=1); @@ -53,9 +53,9 @@ class * @param null|array|getFullyQualifiedName(true); ?> $value * @return null|string */ - public static function assertMinOccurs(string $typeName, string $fieldName, int $expected, null|array| $value): null|string + public static function assertMinOccurs(string $typeName, string $fieldName, int $expected, null|array| $value): null|string { - if (0 >= $expected || (1 === $expected && $value instanceof )) { + if (0 >= $expected || (1 === $expected && $value instanceof )) { return null; } if (null === $value || [] === $value) { @@ -76,9 +76,9 @@ public static function assertMinOccurs(string $typeName, string $fieldName, int * @param null|array|getFullyQualifiedName(true); ?> $value * @return null|string */ - public static function assertMaxOccurs(string $typeName, string $fieldName, int $expected, null|array| $value): null|string + public static function assertMaxOccurs(string $typeName, string $fieldName, int $expected, null|array| $value): null|string { - if (::UNLIMITED === $expected || null === $value || [] === $value || $value instanceof ) { + if (::UNLIMITED === $expected || null === $value || [] === $value || $value instanceof ) { return null; } $len = count($value); @@ -167,12 +167,12 @@ function($v) { return var_export($v, true); }, * @param null|string|getFullyQualifiedName(true); ?> $value * @return null|string */ - public static function assertPatternMatch(string $typeName, string $fieldName, string $pattern, null|string| $value): null|string + public static function assertPatternMatch(string $typeName, string $fieldName, string $pattern, null|string| $value): null|string { if ('' === $pattern || null === $value) { return null; } - if ($value instanceof ) { + if ($value instanceof ) { $value = (string)$value; } if ('' === $value || (bool)preg_match($pattern, $value)) { diff --git a/template/core/versions/interface_version_type_map.php b/template/core/versions/interface_version_type_map.php index f1dc0a6e..39074479 100644 --- a/template/core/versions/interface_version_type_map.php +++ b/template/core/versions/interface_version_type_map.php @@ -24,12 +24,12 @@ $imports = $coreFile->getImports(); $imports->addCoreFileImportsByName( - PHPFHIR_INTERFACE_TYPE + PHPFHIR_TYPES_INTERFACE_TYPE ); $coreFiles = $config->getCoreFiles(); -$typeInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_TYPE); +$typeInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_TYPES_INTERFACE_TYPE); ob_start(); echo 'declare(strict_types=1); @@ -78,7 +78,7 @@ public static function getContainedTypeClassName(string $typeName): null|string; * @return bool * @throws \InvalidArgumentException */ - public static function isContainableResource(string|array|\SimpleXMLElement| $type): bool; + public static function isContainableResource(string|array|\SimpleXMLElement| $type): bool; /** * @param \SimpleXMLElement $node Parent element containing inline resource diff --git a/template/versions/core/class_version_client.php b/template/versions/core/class_version_client.php index b2918c81..189447d3 100644 --- a/template/versions/core/class_version_client.php +++ b/template/versions/core/class_version_client.php @@ -38,7 +38,7 @@ PHPFHIR_EXCEPTION_CLIENT_ERROR, PHPFHIR_EXCEPTION_CLIENT_UNEXPECTED_RESPONSE_CODE, PHPFHIR_CLASSNAME_RESPONSE_PARSER, - PHPFHIR_INTERFACE_TYPE, + PHPFHIR_TYPES_INTERFACE_TYPE, ) ->addVersionTypeImports( $idType, @@ -62,7 +62,7 @@ $clientErrorException = $coreFiles->getCoreFileByEntityName(PHPFHIR_EXCEPTION_CLIENT_ERROR); $clientUnexpectedResponseCodeException = $coreFiles->getCoreFileByEntityName(PHPFHIR_EXCEPTION_CLIENT_UNEXPECTED_RESPONSE_CODE); $responseParserClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_RESPONSE_PARSER); -$typeInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_TYPE); +$typeInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_TYPES_INTERFACE_TYPE); $versionCoreFiles = $version->getCoreFiles(); $versionTypeEnum = $versionCoreFiles->getCoreFileByEntityName(PHPFHIR_VERSION_ENUM_VERSION_TYPES); @@ -175,7 +175,7 @@ public function read( $resource null|string| $sort = null, null| $format = null, null|array $queryParams = null, - null|bool $parseResponseHeaders = null): null| + null|bool $parseResponseHeaders = null): null| { $rc = $this->readRaw($resourceType, $resourceID, $count, $sort, $format, $queryParams, $parseResponseHeaders); diff --git a/template/versions/core/class_version_type_map.php b/template/versions/core/class_version_type_map.php index 87bfca90..42ba77db 100644 --- a/template/versions/core/class_version_type_map.php +++ b/template/versions/core/class_version_type_map.php @@ -26,14 +26,14 @@ $imports->addCoreFileImportsByName( PHPFHIR_CLASSNAME_CONSTANTS, - PHPFHIR_INTERFACE_TYPE, + PHPFHIR_TYPES_INTERFACE_TYPE, PHPFHIR_INTERFACE_VERSION_TYPE_MAP, ); $config = $version->getConfig(); $coreFiles = $config->getCoreFiles(); -$typeInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_TYPE); +$typeInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_TYPES_INTERFACE_TYPE); $types = $version->getDefinition()->getTypes(); @@ -123,11 +123,11 @@ public static function getContainedTypeClassName(string $typeName): null|string * @return bool * @throws \InvalidArgumentException */ - public static function isContainableResource(string|array|\SimpleXMLElement| $type): bool + public static function isContainableResource(string|array|\SimpleXMLElement| $type): bool { $tt = gettype($type); if ('object' === $tt) { - if ($type instanceof ) { + if ($type instanceof ) { return ($type instanceof ); } return isset(self::_CONTAINABLE_TYPES[$type->getName()]); diff --git a/template/versions/core/interface_version_contained_type.php b/template/versions/core/interface_version_contained_type.php index d54fb4b4..d5e80a62 100644 --- a/template/versions/core/interface_version_contained_type.php +++ b/template/versions/core/interface_version_contained_type.php @@ -24,7 +24,7 @@ $imports = $coreFile->getImports(); -$imports->addCoreFileImportsByName(PHPFHIR_INTERFACE_CONTAINED_TYPE); +$imports->addCoreFileImportsByName(PHPFHIR_TYPES_INTERFACE_CONTAINED_TYPE); $config = $version->getConfig(); $types = $version->getDefinition()->getTypes(); @@ -54,7 +54,7 @@ * * This interface is applied to any class that is containable within a getName(); ?> getClassName(); ?> instance */ -interface extends +interface extends { diff --git a/template/versions/types/class_xhtml.php b/template/versions/types/class_xhtml.php index f3911f6b..6de10eb2 100644 --- a/template/versions/types/class_xhtml.php +++ b/template/versions/types/class_xhtml.php @@ -16,6 +16,7 @@ * limitations under the License. */ +use DCarbone\PHPFHIR\Utilities\ImportUtils; use DCarbone\PHPFHIR\Utilities\NameUtils; /** @var \DCarbone\PHPFHIR\Version $version */ @@ -25,27 +26,26 @@ $config = $version->getConfig(); $coreFiles = $config->getCoreFiles(); -$xmlWriterClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_XML_WRITER); -$serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG); +$imports = $type->getimports(); $xmlName = NameUtils::getTypeXMLElementName($type); ob_start(); +echo 'declare(strict_types=1); -// build file header -echo require_with( - PHPFHIR_TEMPLATE_VERSION_TYPES_DIR . '/header.php', - [ - 'version' => $version, - 'type' => $type, - ] -); ?> +namespace getFullyQualifiedNamespace(false); ?>; +getBasePHPFHIRCopyrightComment(true); ?> + + + +class getClassName(); ?> implements \JsonSerializable +{ /** @var string */ private string $_xhtml; /** - * Constructor + * getClassName(); ?> Constructor * @param null|string|\DOMNode|\SimpleXMLElement $xhtml */ public function __construct(null|string|\DOMNode|\SimpleXmlElement $xhtml = null) @@ -149,72 +149,10 @@ public function getXMLReader(int $libxmlOpts): null|\XMLReader return $xr; } - $version, - 'type' => $type, - ] -); -?> - $type->setXHTML($element); - return $type; - } - - $version, - 'type' => $type, - ] -); -?> - $xr = $this->getXMLReader($config->getXHTMLLibxmlOpts()); - if (null === $xr) { - return $xw; - } - while ($xr->moveToNextAttribute()) { - $xw->writeAttribute($xr->name, $xr->value); - } - $xw->writeRaw($xr->readInnerXml()); - if (isset($rootOpened) && $rootOpened) { - $xw->endElement(); - } - if (isset($docStarted) && $docStarted) { - $xw->endDocument(); - } - return $xw; - } - - $version, - 'type' => $type, - ] -); - -// TODO: Right now this assumes a single string value. Need an example use case. -?> - if (null === $json) { - return $type; - } - if ([] !== $json) { - $v = reset($json); - if (is_string($v)) { - $type->setXHTML($v); - } - } - return $type; - } - /** - * @return mixed + * @return null|string */ - public function jsonSerialize(): mixed + public function jsonSerialize(): null|string { if (!isset($this->_xhtml)) { return null; @@ -230,4 +168,4 @@ public function __toString(): string return (string)$this->getXHTML(); } } -getSetterName(); ?>()) { $this-> = []; } + + if (!($ instanceof )) { + $ = new ($); + } $this-> = $; return $this; diff --git a/template/versions/types/serialization/json/unserialize/body.php b/template/versions/types/serialization/json/unserialize/body.php index da477fd0..f7c9995b 100644 --- a/template/versions/types/serialization/json/unserialize/body.php +++ b/template/versions/types/serialization/json/unserialize/body.php @@ -58,7 +58,11 @@ $type->($json[self::]); } -getKind() === TypeKindEnum::PRIMITIVE_CONTAINER || $propType->hasPrimitiveContainerParent() || $propType->isValueContainer()) : ?> +getKind() === TypeKindEnum::PHPFHIR_XHTML) : ?> + if (isset($json[self::]) || array_key_exists(self::, $json)) { + $type->($json[self::]); + } +isPrimitiveContainer() || $propType->hasPrimitiveContainerParent() || $propType->isValueContainer()) : ?> if (isset($json[self::]) || isset($json[self::]) || array_key_exists(self::, $json) || array_key_exists(self::, $json)) { $value = $json[self::] ?? null; $ext = (array)($json[self::] ?? []); diff --git a/template/versions/types/serialization/json/unserialize/header.php b/template/versions/types/serialization/json/unserialize/header.php index f207591a..e3e40cc8 100644 --- a/template/versions/types/serialization/json/unserialize/header.php +++ b/template/versions/types/serialization/json/unserialize/header.php @@ -19,8 +19,6 @@ /** @var \DCarbone\PHPFHIR\Version $version */ /** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ -use DCarbone\PHPFHIR\Enum\TypeKindEnum; - $config = $version->getConfig(); $coreFiles = $config->getCoreFiles(); @@ -36,7 +34,7 @@ * @throws \Exception */ public static function jsonUnserialize(string|array|\stdClass $json, - null| $type = null, + null| $type = null, null| $config = null): self { isAbstract()) : // abstract types may not be instantiated directly ?> diff --git a/template/versions/types/serialization/xml/serialize/body.php b/template/versions/types/serialization/xml/serialize/body.php index 2a31a91e..b37642e0 100644 --- a/template/versions/types/serialization/xml/serialize/body.php +++ b/template/versions/types/serialization/xml/serialize/body.php @@ -128,7 +128,19 @@ $xw->endElement(); } isCollection()) : ?> + elseif ($propTypeKind === TypeKindEnum::PHPFHIR_XHTML) : ?> + if (isset($this->getName(); ?>)) { + $xw->startElement(self::getFieldConstantName(); ?>); + $xr = $this->getName(); ?>->getXMLReader($config->getXHTMLLibxmlOpts()); + if (null !== $xr) { + while ($xr->moveToNextAttribute()) { + $xw->writeAttribute($xr->name, $xr->value); + } + $xw->writeRaw($xr->readInnerXml()); + } + $xw->endElement(); + } +isCollection()) : ?> if (isset($this->getName(); ?>)) { foreach ($this->getName(); ?> as $v) { $xw->startElement(self::getFieldConstantName(); ?>); diff --git a/template/versions/types/serialization/xml/unserialize/body.php b/template/versions/types/serialization/xml/unserialize/body.php index 39b61df8..50383b70 100644 --- a/template/versions/types/serialization/xml/unserialize/body.php +++ b/template/versions/types/serialization/xml/unserialize/body.php @@ -60,6 +60,8 @@ $cn = ::getContainedTypeClassNameFromXML($nn); $type->($cn::xmlUnserialize($nn, null, $config)); } + + $type->($n); getMemberOf()->getImports()->getImportByType($propType); ?> $v = new (valueXMLLocation: ::ELEMENT); @@ -76,8 +78,9 @@ $setter = $property->getSetterName(); $requiresXMLLocation = $propType === null + || $propType->isPrimitiveOrListType() + || $propType->isPrimitiveContainer() || $propType->isValueContainer() - || $propType->getKind()->isOneOf(TypeKindEnum::LIST, TypeKindEnum::PRIMITIVE, TypeKindEnum::PRIMITIVE_CONTAINER) || $propType->hasPrimitiveOrListParent() || $propType->hasValueContainerParent() || $propType->hasPrimitiveContainerParent(); diff --git a/template/versions/types/serialization/xml/unserialize/header.php b/template/versions/types/serialization/xml/unserialize/header.php index 2d8f1db9..c25b8cdf 100644 --- a/template/versions/types/serialization/xml/unserialize/header.php +++ b/template/versions/types/serialization/xml/unserialize/header.php @@ -36,7 +36,7 @@ * @throws \Exception */ public static function xmlUnserialize(string|\SimpleXMLElement $element, - null| $type = null, + null| $type = null, null| $config = null): self { isAbstract()) : // abstract types may not be instantiated directly ?>