Skip to content

Commit

Permalink
merged branch benji07/patch-1 (PR #8416)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fabpot committed Aug 2, 2013
2 parents 2cc36f1 + 5c27d7e commit b788094
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/Serializer/CHANGELOG.md
@@ -1,6 +1,11 @@
CHANGELOG
=========

2.4.0
-----

* added `$context` support for XMLEncoder.

2.3.0
-----

Expand Down
6 changes: 4 additions & 2 deletions src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
Expand Up @@ -24,6 +24,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
{
private $dom;
private $format;
private $context;
private $rootNodeName = 'response';

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

$this->dom = $this->createDomDocument($context);
$this->format = $format;
$this->context = $context;

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

if (is_object($data)) {
$data = $this->serializer->normalize($data, $this->format);
$data = $this->serializer->normalize($data, $this->format, $this->context);
if (null !== $data && !is_scalar($data)) {
return $this->buildXml($parentNode, $data, $xmlRootNodeName);
}
Expand Down Expand Up @@ -399,7 +401,7 @@ private function selectNodeType($node, $val)
} elseif ($val instanceof \Traversable) {
$this->buildXml($node, $val);
} elseif (is_object($val)) {
return $this->buildXml($node, $this->serializer->normalize($val, $this->format));
return $this->buildXml($node, $this->serializer->normalize($val, $this->format, $this->context));
} elseif (is_numeric($val)) {
return $this->appendText($node, (string) $val);
} elseif (is_string($val) && $this->needsCdataWrapping($val)) {
Expand Down

0 comments on commit b788094

Please sign in to comment.