Skip to content

Improve the XML serialization of numeric types #1469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ private function dumpXmlShape(Member $member, Shape $shape, string $output, stri
switch ($shape->getType()) {
case 'blob':
case 'string':
return $this->dumpXmlShapeString($member, $shape, $output, $input);
case 'integer':
case 'long':
case 'float':
case 'double':
return $this->dumpXmlShapeString($member, $shape, $output, $input);
return $this->dumpXmlShapeNumeric($member, $output, $input);
case 'boolean':
return $this->dumpXmlShapeBoolean($member, $output, $input);
}
Expand Down Expand Up @@ -230,6 +231,23 @@ private function dumpXmlShapeString(Member $member, Shape $shape, string $output
return strtr($body, $replacements);
}

private function dumpXmlShapeNumeric(Member $member, string $output, string $input): string
{
if ($member instanceof StructureMember && $member->isXmlAttribute()) {
$body = 'OUTPUT->setAttribute(NODE_NAME, (string) INPUT);';
} else {
$body = 'OUTPUT->appendChild($document->createElement(NODE_NAME, (string) INPUT));';
}

$replacements = [
'INPUT' => $input,
'OUTPUT' => $output,
'NODE_NAME' => var_export($member->getLocationName() ?? ($member instanceof StructureMember ? $member->getName() : 'member'), true),
];

return strtr($body, $replacements);
}

private function dumpXmlShapeBoolean(Member $member, string $output, string $input): string
{
if ($member instanceof StructureMember && $member->isXmlAttribute()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Service/CloudFront/src/ValueObject/Paths.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void
if (null === $v = $this->quantity) {
throw new InvalidArgument(sprintf('Missing parameter "Quantity" for "%s". The value cannot be null.', __CLASS__));
}
$node->appendChild($document->createElement('Quantity', $v));
$node->appendChild($document->createElement('Quantity', (string) $v));
if (null !== $v = $this->items) {
$node->appendChild($nodeList = $document->createElement('Items'));
foreach ($v as $item) {
Expand Down
4 changes: 2 additions & 2 deletions src/Service/Route53/src/ValueObject/ResourceRecordSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void
$node->appendChild($document->createElement('SetIdentifier', $v));
}
if (null !== $v = $this->weight) {
$node->appendChild($document->createElement('Weight', $v));
$node->appendChild($document->createElement('Weight', (string) $v));
}
if (null !== $v = $this->region) {
if (!ResourceRecordSetRegion::exists($v)) {
Expand All @@ -564,7 +564,7 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void
$node->appendChild($document->createElement('MultiValueAnswer', $v ? 'true' : 'false'));
}
if (null !== $v = $this->ttl) {
$node->appendChild($document->createElement('TTL', $v));
$node->appendChild($document->createElement('TTL', (string) $v));
}
if (null !== $v = $this->resourceRecords) {
$node->appendChild($nodeList = $document->createElement('ResourceRecords'));
Expand Down
2 changes: 1 addition & 1 deletion src/Service/S3/src/ValueObject/CORSRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void
}
}
if (null !== $v = $this->maxAgeSeconds) {
$node->appendChild($document->createElement('MaxAgeSeconds', $v));
$node->appendChild($document->createElement('MaxAgeSeconds', (string) $v));
}
}
}
2 changes: 1 addition & 1 deletion src/Service/S3/src/ValueObject/CompletedPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void
$node->appendChild($document->createElement('ChecksumSHA256', $v));
}
if (null !== $v = $this->partNumber) {
$node->appendChild($document->createElement('PartNumber', $v));
$node->appendChild($document->createElement('PartNumber', (string) $v));
}
}
}