Skip to content

Commit

Permalink
fixing xml unesrialize for inherited types
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Apr 25, 2024
1 parent ae01e6e commit ad02089
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions template/types/serialization/xml/unserialize/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,30 @@ public static function xmlUnserialize(null|string|\DOMNode $element, null|<?php
libxml_use_internal_errors(true);
$dom = new \DOMDocument();
if (false === $dom->loadXML($element, $libxmlOpts)) {
throw new \DomainException(sprintf('<?php echo $typeClassName; ?>::xmlUnserialize - String provided is not parseable as XML: %s', implode(', ', array_map(function(\libXMLError $err) { return $err->message; }, libxml_get_errors()))));
throw new \DomainException(sprintf(
'%s::xmlUnserialize - String provided is not parseable as XML: %s',
static::class,
implode(', ', array_map(function(\libXMLError $err) { return $err->message; }, libxml_get_errors()))
));
}
libxml_use_internal_errors(false);
$element = $dom->documentElement;
}
<?php if ($type->isAbstract()) : // abstract types may not be instantiated directly ?>
if (null === $type) {
throw new \RuntimeException('<?php echo $typeClassName; ?>::xmlUnserialize: Cannot unserialize directly into root type');
} else if (!($type instanceof <?php echo $typeClassName; ?>)) {
throw new \RuntimeException(sprintf(
'<?php echo $typeClassName; ?>::xmlUnserialize - $type must be child instance of %s or null, %s seen.',
static::class,
get_class($type)
));
throw new \RuntimeException(sprintf('%s::xmlUnserialize: Cannot unserialize directly into root type', static::class));
}
<?php else : ?>
if (null === $type) {
$type = new <?php echo $typeClassName; ?>(null);
} else if (!($type instanceof <?php echo $typeClassName; ?>)) {
$type = new static(null);
}<?php endif; ?> else if (!($type instanceof <?php echo $typeClassName; ?>)) {
throw new \RuntimeException(sprintf(
'<?php echo $typeClassName; ?>::xmlUnserialize - $type must be instance of %s or null, %s seen.',
'%s::xmlUnserialize - $type must be instance of \\%s or null, %s seen.',
ltrim(substr(__CLASS__, (int)strrpos(__CLASS__, '\\')), '\\'),
static::class,
get_class($type)
));
}
<?php endif; ?>
if ('' === $type->_getFHIRXMLNamespace() && '' !== ($ens = (string)$element->namespaceURI)) {
$type->_setFHIRXMLNamespace($ens);
}
Expand Down

0 comments on commit ad02089

Please sign in to comment.