Skip to content

Commit 53cf2f9

Browse files
committed
merged branch benji07/patch-1 (PR #8416)
This PR was squashed before being merged into the master branch (closes #8416). Discussion ---------- [Serializer] Add the missing context support inside the XmlEncoder | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | $context variable was added in symfony 2.3 but not inside this encoder Commits ------- 5c27d7e [Serializer] Add the missing context support inside the XmlEncoder
2 parents 3f63e19 + 6004596 commit 53cf2f9

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 = $this->createDomDocument($context);
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)