diff --git a/UPGRADE-2.2.md b/UPGRADE-2.2.md index 8dc849d5137f..62297d1b3637 100644 --- a/UPGRADE-2.2.md +++ b/UPGRADE-2.2.md @@ -383,3 +383,9 @@ framework: trusted_proxies: ['127.0.0.1', '10.0.0.1'] # a list of proxy IPs you trust ``` + +#### Serializer + + * All serializer interfaces (Serializer, Normalizer, Encoder) have been extended with an optional ``$context`` array. + This was necessary to allow for more complex use-cases that require context information during the (de)normalization + and en-/decoding steps. diff --git a/src/Symfony/Component/Serializer/Encoder/ChainDecoder.php b/src/Symfony/Component/Serializer/Encoder/ChainDecoder.php index f555c6a8c982..6ece3b2205b9 100644 --- a/src/Symfony/Component/Serializer/Encoder/ChainDecoder.php +++ b/src/Symfony/Component/Serializer/Encoder/ChainDecoder.php @@ -34,9 +34,9 @@ public function __construct(array $decoders = array()) /** * {@inheritdoc} */ - final public function decode($data, $format) + final public function decode($data, $format, array $context = array()) { - return $this->getDecoder($format)->decode($data, $format); + return $this->getDecoder($format)->decode($data, $format, $context); } /** diff --git a/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php b/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php index ebb81efb9ff3..bd10a2ad412a 100644 --- a/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php @@ -35,9 +35,9 @@ public function __construct(array $encoders = array()) /** * {@inheritdoc} */ - final public function encode($data, $format) + final public function encode($data, $format, array $context = array()) { - return $this->getEncoder($format)->encode($data, $format); + return $this->getEncoder($format)->encode($data, $format, $context); } /** diff --git a/src/Symfony/Component/Serializer/Encoder/DecoderInterface.php b/src/Symfony/Component/Serializer/Encoder/DecoderInterface.php index e95271f740b0..ffd221fe8d58 100644 --- a/src/Symfony/Component/Serializer/Encoder/DecoderInterface.php +++ b/src/Symfony/Component/Serializer/Encoder/DecoderInterface.php @@ -23,10 +23,11 @@ interface DecoderInterface * * @param scalar $data Data to decode * @param string $format Format name + * @param array $context options that decoders have access to. * * @return mixed */ - public function decode($data, $format); + public function decode($data, $format, array $context = array()); /** * Checks whether the serializer can decode from given format diff --git a/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php b/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php index 4a68ad3fe9ea..2290db7f50d8 100644 --- a/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php +++ b/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php @@ -23,10 +23,11 @@ interface EncoderInterface * * @param mixed $data Data to encode * @param string $format Format name + * @param array $context options that normalizers/encoders have access to. * * @return scalar */ - public function encode($data, $format); + public function encode($data, $format, array $context = array()); /** * Checks whether the serializer can encode to given format diff --git a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php index f0d41919e2d8..7d3ad82ee31a 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php @@ -11,15 +11,12 @@ namespace Symfony\Component\Serializer\Encoder; -use Symfony\Component\Serializer\SerializerInterface; -use Symfony\Component\Serializer\SerializerAwareInterface; - /** * Decodes JSON data * * @author Sander Coolen */ -class JsonDecode implements DecoderInterface, SerializerAwareInterface +class JsonDecode implements DecoderInterface { private $associative; private $recursionDepth; @@ -52,13 +49,13 @@ public function getLastError() * * @return mixed */ - public function decode($data, $format) + public function decode($data, $format, array $context = array()) { - $context = $this->getContext(); + $context = $this->resolveContext($context); - $associative = $context['associative']; - $recursionDepth = $context['recursionDepth']; - $options = $context['options']; + $associative = $context['json_decode_associative']; + $recursionDepth = $context['json_decode_recursion_depth']; + $options = $context['json_decode_options']; $decodedData = json_decode($data, $associative, $recursionDepth, $options); $this->lastError = json_last_error(); @@ -75,45 +72,19 @@ public function supportsDecoding($format) } /** - * {@inheritdoc} + * Merge the default options of the Json Decoder with the passed context. + * + * @param array $context + * @return array */ - public function setSerializer(SerializerInterface $serializer) + private function resolveContext(array $context) { - $this->serializer = $serializer; - } - - private function getContext() - { - $options = array( - 'associative' => $this->associative, - 'recursionDepth' => $this->recursionDepth, - 'options' => 0 + $defaultOptions = array( + 'json_decode_associative' => $this->associative, + 'json_decode_recursion_depth' => $this->recursionDepth, + 'json_decode_options' => 0 ); - if (!$this->serializer) { - return $options; - } - - $options = array( - 'associative' => false, - 'recursionDepth' => 512, - 'options' => 0 - ); - - $context = $this->serializer->getContext(); - - if (isset($context['associative'])) { - $options['associative'] = $context['associative']; - } - - if (isset($context['recursionDepth'])) { - $options['recursionDepth'] = $context['recursionDepth']; - } - - if (isset($context['options'])) { - $options['options'] = $context['options']; - } - - return $options; + return array_merge($defaultOptions, $context); } } diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php index 623578e810ec..4e0de3ed7589 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php @@ -16,7 +16,7 @@ * * @author Sander Coolen */ -class JsonEncode extends SerializerAwareEncoder implements EncoderInterface +class JsonEncode implements EncoderInterface { private $options ; private $lastError = JSON_ERROR_NONE; @@ -41,16 +41,13 @@ public function getLastError() /** * Encodes PHP data to a JSON string * - * @param mixed $data - * @param string $format - * - * @return string + * {@inheritdoc} */ - public function encode($data, $format) + public function encode($data, $format, array $context = array()) { - $options = $this->getContext(); + $context = $this->resolveContext($context); - $encodedJson = json_encode($data, $options); + $encodedJson = json_encode($data, $context['json_encode_options']); $this->lastError = json_last_error(); return $encodedJson; @@ -64,22 +61,14 @@ public function supportsEncoding($format) return JsonEncoder::FORMAT === $format; } - private function getContext() + /** + * Merge default json encode options with context. + * + * @param array $context + * @return array + */ + private function resolveContext(array $context = array()) { - if (!$this->serializer) { - return 0; - } - - $context = $this->serializer->getContext(); - - if (empty($context)) { - $context = array(0); - } - - if (!is_array($context)) { - $context = array($context); - } - - return array_sum($context); + return array_merge(array('json_encode_options' => $this->options), $context); } } diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php b/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php index fff2fd501626..02b179bc91a6 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php @@ -16,7 +16,7 @@ * * @author Jordi Boggiano */ -class JsonEncoder extends SerializerAwareEncoder implements EncoderInterface, DecoderInterface +class JsonEncoder implements EncoderInterface, DecoderInterface { const FORMAT = 'json'; @@ -59,21 +59,17 @@ public function getLastDecodingError() /** * {@inheritdoc} */ - public function encode($data, $format) + public function encode($data, $format, array $context = array()) { - $this->encodingImpl->setSerializer($this->serializer); - - return $this->encodingImpl->encode($data, self::FORMAT); + return $this->encodingImpl->encode($data, self::FORMAT, $context); } /** * {@inheritdoc} */ - public function decode($data, $format) + public function decode($data, $format, array $context = array()) { - $this->decodingImpl->setSerializer($this->serializer); - - return $this->decodingImpl->decode($data, self::FORMAT); + return $this->decodingImpl->decode($data, self::FORMAT, $context); } /** diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index d1ed33920a12..909b3cefe7b4 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -26,24 +26,36 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec private $format; private $rootNodeName = 'response'; + /** + * Construct new XmlEncoder and allow to change the root node element name. + * + * @param string $rootNodeName + */ + public function __construct($rootNodeName = 'response') + { + $this->rootNodeName = $rootNodeName; + } + /** * {@inheritdoc} */ - public function encode($data, $format) + public function encode($data, $format, array $context = array()) { if ($data instanceof \DOMDocument) { return $data->saveXML(); } + $xmlRootNodeName = $this->resolveXmlRootName($context); + $this->dom = new \DOMDocument(); $this->format = $format; if (null !== $data && !is_scalar($data)) { - $root = $this->dom->createElement($this->getRealRootNodeName()); + $root = $this->dom->createElement($xmlRootNodeName); $this->dom->appendChild($root); - $this->buildXml($root, $data); + $this->buildXml($root, $data, $xmlRootNodeName); } else { - $this->appendNode($this->dom, $data, $this->getRealRootNodeName()); + $this->appendNode($this->dom, $data, $xmlRootNodeName); } return $this->dom->saveXML(); @@ -52,7 +64,7 @@ public function encode($data, $format) /** * {@inheritdoc} */ - public function decode($data, $format) + public function decode($data, $format, array $context = array()) { $internalErrors = libxml_use_internal_errors(true); $disableEntities = libxml_disable_entity_loader(true); @@ -269,12 +281,13 @@ private function parseXml($node) * * @param DOMNode $parentNode * @param array|object $data data + * @param string $xmlRootNodeName * * @return Boolean * * @throws UnexpectedValueException */ - private function buildXml($parentNode, $data) + private function buildXml($parentNode, $data, $xmlRootNodeName) { $append = true; @@ -310,21 +323,24 @@ private function buildXml($parentNode, $data) return $append; } + if (is_object($data)) { $data = $this->serializer->normalize($data, $this->format); if (null !== $data && !is_scalar($data)) { - return $this->buildXml($parentNode, $data); + return $this->buildXml($parentNode, $data, $xmlRootNodeName); } + // top level data object was normalized into a scalar if (!$parentNode->parentNode->parentNode) { $root = $parentNode->parentNode; $root->removeChild($parentNode); - return $this->appendNode($root, $data, $this->getRealRootNodeName()); + return $this->appendNode($root, $data, $xmlRootNodeName); } return $this->appendNode($parentNode, $data, 'data'); } + throw new UnexpectedValueException('An unexpected value could not be serialized: '.var_export($data, true)); } @@ -376,7 +392,7 @@ private function needsCdataWrapping($val) private function selectNodeType($node, $val) { if (is_array($val)) { - return $this->buildXml($node, $val); + return $this->buildXml($node, $val, null); } elseif ($val instanceof \SimpleXMLElement) { $child = $this->dom->importNode(dom_import_simplexml($val), true); $node->appendChild($child); @@ -403,14 +419,8 @@ private function selectNodeType($node, $val) /** * Get real XML root node name, taking serializer options into account. */ - private function getRealRootNodeName() + private function resolveXmlRootName(array $context = array()) { - if (!$this->serializer) { - return $this->rootNodeName; - } - - $context = $this->serializer->getContext(); - return isset($context['xml_root_node_name']) ? $context['xml_root_node_name'] : $this->rootNodeName; diff --git a/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php index 4510fa0b8006..0ebe00fda54f 100644 --- a/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php @@ -19,18 +19,18 @@ class CustomNormalizer extends SerializerAwareNormalizer implements NormalizerIn /** * {@inheritdoc} */ - public function normalize($object, $format = null) + public function normalize($object, $format = null, array $context = array()) { - return $object->normalize($this->serializer, $format); + return $object->normalize($this->serializer, $format, $context); } /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = null) + public function denormalize($data, $class, $format = null, array $context = array()) { $object = new $class; - $object->denormalize($this->serializer, $data, $format); + $object->denormalize($this->serializer, $data, $format, $context); return $object; } diff --git a/src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php b/src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php index 3f3bf883238d..5a1b4c196b59 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/DenormalizableInterface.php @@ -32,6 +32,7 @@ interface DenormalizableInterface * @param array|scalar $data The data from which to re-create the object. * @param string|null $format The format is optionally given to be able to denormalize differently * based on different input formats. + * @param array $context options for denormalizing */ - public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null); + public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null, array $context = array()); } diff --git a/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php index 384f9febb668..1a5ff93f751d 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php @@ -24,10 +24,11 @@ interface DenormalizerInterface * @param mixed $data data to restore * @param string $class the expected class to instantiate * @param string $format format the given data was extracted from + * @param array $context options available to the denormalizer * * @return object */ - public function denormalize($data, $class, $format = null); + public function denormalize($data, $class, $format = null, array $context = array()); /** * Checks whether the given class is supported for denormalization by this normalizer diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index 2c5f1b3e874d..63e7a1dea91e 100644 --- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php @@ -69,7 +69,7 @@ public function setIgnoredAttributes(array $ignoredAttributes) /** * {@inheritdoc} */ - public function normalize($object, $format = null) + public function normalize($object, $format = null, array $context = array()) { $reflectionObject = new \ReflectionObject($object); $reflectionMethods = $reflectionObject->getMethods(\ReflectionMethod::IS_PUBLIC); @@ -101,7 +101,7 @@ public function normalize($object, $format = null) /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = null) + public function denormalize($data, $class, $format = null, array $context = array()) { $reflectionClass = new \ReflectionClass($class); $constructor = $reflectionClass->getConstructor(); diff --git a/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php b/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php index fb77a836d8d9..07c3a4a8dd8e 100644 --- a/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php @@ -31,8 +31,9 @@ interface NormalizableInterface * can use it to normalize objects contained within this object. * @param string|null $format The format is optionally given to be able to normalize differently * based on different output formats. + * @param array $context Options for normalizing this object * * @return array|scalar */ - public function normalize(NormalizerInterface $normalizer, $format = null); + public function normalize(NormalizerInterface $normalizer, $format = null, array $context = array()); } diff --git a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php index f0915db2b453..744307a2ba37 100644 --- a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php @@ -23,10 +23,11 @@ interface NormalizerInterface * * @param object $object object to normalize * @param string $format format the normalization result will be encoded as + * @param array $context Context options for the normalizer * * @return array|scalar */ - public function normalize($object, $format = null); + public function normalize($object, $format = null, array $context = array()); /** * Checks whether the given class is supported for normalization by this normalizer diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index 6a84b10efcef..ab6fd58b5fde 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -42,7 +42,6 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz protected $normalizers = array(); protected $normalizerCache = array(); protected $denormalizerCache = array(); - protected $context; public function __construct(array $normalizers = array(), array $encoders = array()) { @@ -79,13 +78,11 @@ final public function serialize($data, $format, array $context = array()) throw new UnexpectedValueException('Serialization for the format '.$format.' is not supported'); } - $this->context = $context; - if ($this->encoder->needsNormalization($format)) { - $data = $this->normalize($data, $format); + $data = $this->normalize($data, $format, $context); } - return $this->encode($data, $format); + return $this->encode($data, $format, $context); } /** @@ -97,38 +94,36 @@ final public function deserialize($data, $type, $format, array $context = array( throw new UnexpectedValueException('Deserialization for the format '.$format.' is not supported'); } - $this->context = $context; - - $data = $this->decode($data, $format); + $data = $this->decode($data, $format, $context); - return $this->denormalize($data, $type, $format); + return $this->denormalize($data, $type, $format, $context); } /** * {@inheritdoc} */ - public function normalize($data, $format = null) + public function normalize($data, $format = null, array $context = array()) { if (null === $data || is_scalar($data)) { return $data; } if (is_object($data) && $this->supportsNormalization($data, $format)) { - return $this->normalizeObject($data, $format); + return $this->normalizeObject($data, $format, $context); } if ($data instanceof \Traversable) { $normalized = array(); foreach ($data as $key => $val) { - $normalized[$key] = $this->normalize($val, $format); + $normalized[$key] = $this->normalize($val, $format, $context); } return $normalized; } if (is_object($data)) { - return $this->normalizeObject($data, $format); + return $this->normalizeObject($data, $format, $context); } if (is_array($data)) { foreach ($data as $key => $val) { - $data[$key] = $this->normalize($val, $format); + $data[$key] = $this->normalize($val, $format, $context); } return $data; @@ -139,9 +134,9 @@ public function normalize($data, $format = null) /** * {@inheritdoc} */ - public function denormalize($data, $type, $format = null) + public function denormalize($data, $type, $format = null, array $context = array()) { - return $this->denormalizeObject($data, $type, $format); + return $this->denormalizeObject($data, $type, $format, $context); } /** @@ -207,17 +202,17 @@ private function getDenormalizer($data, $type, $format = null) /** * {@inheritdoc} */ - final public function encode($data, $format) + final public function encode($data, $format, array $context = array()) { - return $this->encoder->encode($data, $format); + return $this->encoder->encode($data, $format, $context); } /** * {@inheritdoc} */ - final public function decode($data, $format) + final public function decode($data, $format, array $context = array()) { - return $this->decoder->decode($data, $format); + return $this->decoder->decode($data, $format, $context); } /** @@ -225,13 +220,14 @@ final public function decode($data, $format) * * @param object $object object to normalize * @param string $format format name, present to give the option to normalizers to act differently based on formats + * @param array $context The context data for this particular normalization * * @return array|scalar * * @throws LogicException * @throws UnexpectedValueException */ - private function normalizeObject($object, $format = null) + private function normalizeObject($object, $format = null, array $context = array()) { if (!$this->normalizers) { throw new LogicException('You must register at least one normalizer to be able to normalize objects.'); @@ -239,14 +235,14 @@ private function normalizeObject($object, $format = null) $class = get_class($object); if (isset($this->normalizerCache[$class][$format])) { - return $this->normalizerCache[$class][$format]->normalize($object, $format); + return $this->normalizerCache[$class][$format]->normalize($object, $format, $context); } foreach ($this->normalizers as $normalizer) { if ($normalizer->supportsNormalization($object, $format)) { $this->normalizerCache[$class][$format] = $normalizer; - return $normalizer->normalize($object, $format); + return $normalizer->normalize($object, $format, $context); } } @@ -259,27 +255,28 @@ private function normalizeObject($object, $format = null) * @param mixed $data data to restore * @param string $class the expected class to instantiate * @param string $format format name, present to give the option to normalizers to act differently based on formats + * @param array $context The context data for this particular denormalization * * @return object * * @throws LogicException * @throws UnexpectedValueException */ - private function denormalizeObject($data, $class, $format = null) + private function denormalizeObject($data, $class, $format = null, array $context = array()) { if (!$this->normalizers) { throw new LogicException('You must register at least one normalizer to be able to denormalize objects.'); } if (isset($this->denormalizerCache[$class][$format])) { - return $this->denormalizerCache[$class][$format]->denormalize($data, $class, $format); + return $this->denormalizerCache[$class][$format]->denormalize($data, $class, $format, $context); } foreach ($this->normalizers as $normalizer) { if ($normalizer->supportsDenormalization($data, $class, $format)) { $this->denormalizerCache[$class][$format] = $normalizer; - return $normalizer->denormalize($data, $class, $format); + return $normalizer->denormalize($data, $class, $format, $context); } } @@ -301,12 +298,4 @@ public function supportsDecoding($format) { return $this->decoder->supportsDecoding($format); } - - /** - * {@inheritdoc} - */ - public function getContext() - { - return $this->context; - } } diff --git a/src/Symfony/Component/Serializer/SerializerInterface.php b/src/Symfony/Component/Serializer/SerializerInterface.php index a0fc5120895a..d196d780a95b 100644 --- a/src/Symfony/Component/Serializer/SerializerInterface.php +++ b/src/Symfony/Component/Serializer/SerializerInterface.php @@ -40,11 +40,4 @@ public function serialize($data, $format, array $context = array()); * @return object */ public function deserialize($data, $type, $format, array $context = array()); - - /** - * Get current options of the serializer - * - * @return array - */ - public function getContext(); } diff --git a/src/Symfony/Component/Serializer/Tests/Encoder/JsonEncoderTest.php b/src/Symfony/Component/Serializer/Tests/Encoder/JsonEncoderTest.php index 5a525c31c341..c2f60728d96d 100644 --- a/src/Symfony/Component/Serializer/Tests/Encoder/JsonEncoderTest.php +++ b/src/Symfony/Component/Serializer/Tests/Encoder/JsonEncoderTest.php @@ -21,7 +21,6 @@ protected function setUp() { $this->encoder = new JsonEncoder; $this->serializer = new Serializer(array(new CustomNormalizer()), array('json' => new JsonEncoder())); - $this->encoder->setSerializer($this->serializer); } public function testEncodeScalar() @@ -45,7 +44,7 @@ public function testComplexObject() public function testOptions() { - $context = array(JSON_NUMERIC_CHECK); + $context = array('json_encode_options' => JSON_NUMERIC_CHECK); $arr = array(); $arr['foo'] = "3"; diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/DenormalizableDummy.php b/src/Symfony/Component/Serializer/Tests/Fixtures/DenormalizableDummy.php index 468d44487645..09b8a5281216 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/DenormalizableDummy.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/DenormalizableDummy.php @@ -17,7 +17,7 @@ class DenormalizableDummy implements DenormalizableInterface { - public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null) + public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null, array $context = array()) { } diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/Dummy.php b/src/Symfony/Component/Serializer/Tests/Fixtures/Dummy.php index cdcf510df0a2..6b33e8437440 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/Dummy.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/Dummy.php @@ -23,7 +23,7 @@ class Dummy implements NormalizableInterface, DenormalizableInterface public $baz; public $qux; - public function normalize(NormalizerInterface $normalizer, $format = null) + public function normalize(NormalizerInterface $normalizer, $format = null, array $context = array()) { return array( 'foo' => $this->foo, @@ -33,7 +33,7 @@ public function normalize(NormalizerInterface $normalizer, $format = null) ); } - public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null) + public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null, array $context = array()) { $this->foo = $data['foo']; $this->bar = $data['bar']; diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/NormalizableTraversableDummy.php b/src/Symfony/Component/Serializer/Tests/Fixtures/NormalizableTraversableDummy.php index ba1f924e015f..3ac2fe364f9a 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/NormalizableTraversableDummy.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/NormalizableTraversableDummy.php @@ -18,7 +18,7 @@ class NormalizableTraversableDummy extends TraversableDummy implements NormalizableInterface, DenormalizableInterface { - public function normalize(NormalizerInterface $normalizer, $format = null) + public function normalize(NormalizerInterface $normalizer, $format = null, array $context = array()) { return array( 'foo' => 'normalizedFoo', @@ -26,7 +26,7 @@ public function normalize(NormalizerInterface $normalizer, $format = null) ); } - public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null) + public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null, array $context = array()) { return array( 'foo' => 'denormalizedFoo', diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/ScalarDummy.php b/src/Symfony/Component/Serializer/Tests/Fixtures/ScalarDummy.php index 1b0516a4174e..e9db23882b58 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/ScalarDummy.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/ScalarDummy.php @@ -21,12 +21,12 @@ class ScalarDummy implements NormalizableInterface, DenormalizableInterface public $foo; public $xmlFoo; - public function normalize(NormalizerInterface $normalizer, $format = null) + public function normalize(NormalizerInterface $normalizer, $format = null, array $context = array()) { return $format === 'xml' ? $this->xmlFoo : $this->foo; } - public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null) + public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null, array $context = array()) { if ($format === 'xml') { $this->xmlFoo = $data;