@@ -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