Skip to content

Commit 6004596

Browse files
benji07fabpot
authored andcommitted
[Serializer] Add the missing context support inside the XmlEncoder
1 parent b6eb7ec commit 6004596

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
2.4.0
5+
-----
6+
7+
* added `$context` support for XMLEncoder.
8+
49
2.3.0
510
-----
611

Encoder/XmlEncoder.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
2424
{
2525
private $dom;
2626
private $format;
27+
private $context;
2728
private $rootNodeName = 'response';
2829

2930
/**
@@ -49,6 +50,7 @@ public function encode($data, $format, array $context = array())
4950

5051
$this->dom = new \DOMDocument();
5152
$this->format = $format;
53+
$this->context = $context;
5254

5355
if (null !== $data && !is_scalar($data)) {
5456
$root = $this->dom->createElement($xmlRootNodeName);
@@ -325,7 +327,7 @@ private function buildXml($parentNode, $data, $xmlRootNodeName = null)
325327
}
326328

327329
if (is_object($data)) {
328-
$data = $this->serializer->normalize($data, $this->format);
330+
$data = $this->serializer->normalize($data, $this->format, $this->context);
329331
if (null !== $data && !is_scalar($data)) {
330332
return $this->buildXml($parentNode, $data, $xmlRootNodeName);
331333
}
@@ -399,7 +401,7 @@ private function selectNodeType($node, $val)
399401
} elseif ($val instanceof \Traversable) {
400402
$this->buildXml($node, $val);
401403
} elseif (is_object($val)) {
402-
return $this->buildXml($node, $this->serializer->normalize($val, $this->format));
404+
return $this->buildXml($node, $this->serializer->normalize($val, $this->format, $this->context));
403405
} elseif (is_numeric($val)) {
404406
return $this->appendText($node, (string) $val);
405407
} elseif (is_string($val) && $this->needsCdataWrapping($val)) {

0 commit comments

Comments
 (0)