Skip to content

Commit

Permalink
Add checks in getStructureMembers to make sure array_keys are actuall…
Browse files Browse the repository at this point in the history
…y members
  • Loading branch information
jeskew committed Jun 23, 2015
1 parent 384c525 commit bbf8c09
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/Api/Serializer/XmlBody.php
Expand Up @@ -90,34 +90,39 @@ private function add_structure(
) {
$this->startElement($shape, $name, $xml);

foreach ($this->sortMembers($shape, $value) as $k => $v) {
if ($v !== null && $shape->hasMember($k)) {
$member = $shape->getMember($k);
$elementName = $member['locationName'] ?: $k;
$this->format($member, $elementName, $v, $xml);
}
foreach ($this->getStructureMembers($shape, $value) as $k => $definition) {
$this->format(
$definition['member'],
$definition['member']['locationName'] ?: $k,
$definition['value'],
$xml
);
}

$xml->endElement();
}

private function sortMembers(StructureShape $shape, array $value)
private function getStructureMembers(StructureShape $shape, array $value)
{
$sortedValue = [];
$members = [];

// uksort is not appropriate here, as the order of children must be
// maintained for compliance testing. The only thing we want to do is
// bubble attributes to the top of the list so that XMLWriter will
// actually write them.
foreach ($value as $k => $v) {
if ($shape->getMember($k)['xmlAttribute']) {
$sortedValue = [$k => $v] + $sortedValue;
} else {
$sortedValue[$k] = $v;
if ($v !== null && $shape->hasMember($k)) {
$definition = [
'member' => $shape->getMember($k),
'value' => $v,
];

if ($definition['member']['xmlAttribute']) {
// array_unshift_associative
$members = [$k => $definition] + $members;
} else {
$members[$k] = $definition;
}
}
}

return $sortedValue;
return $members;
}

private function add_list(
Expand Down

0 comments on commit bbf8c09

Please sign in to comment.