diff --git a/Encoder/XmlEncoder.php b/Encoder/XmlEncoder.php index a5d86afe9..4d6ac6204 100644 --- a/Encoder/XmlEncoder.php +++ b/Encoder/XmlEncoder.php @@ -405,7 +405,7 @@ private function selectNodeType($node, $val) */ private function getRealRootNodeName() { - if ( ! $this->serializer) { + if (!$this->serializer) { return $this->rootNodeName; } diff --git a/Serializer.php b/Serializer.php index d1c7138d6..4ec09b071 100644 --- a/Serializer.php +++ b/Serializer.php @@ -42,9 +42,9 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz protected $normalizers = array(); protected $normalizerCache = array(); protected $denormalizerCache = array(); - protected $options = array(); + protected $options; - public function __construct(array $normalizers = array(), array $encoders = array(), array $options = array()) + public function __construct(array $normalizers = array(), array $encoders = array()) { foreach ($normalizers as $normalizer) { if ($normalizer instanceof SerializerAwareInterface) { @@ -68,7 +68,6 @@ public function __construct(array $normalizers = array(), array $encoders = arra } $this->encoder = new ChainEncoder($realEncoders); $this->decoder = new ChainDecoder($decoders); - $this->options = $options; } /** @@ -80,7 +79,7 @@ final public function serialize($data, $format, array $options = array()) throw new UnexpectedValueException('Serialization for the format '.$format.' is not supported'); } - $this->options = array_merge($this->options, $options); + $this->options = $options; if ($this->encoder->needsNormalization($format)) { $data = $this->normalize($data, $format); @@ -98,7 +97,7 @@ final public function deserialize($data, $type, $format, array $options = array( throw new UnexpectedValueException('Deserialization for the format '.$format.' is not supported'); } - $this->options = array_merge($this->options, $options); + $this->options = $options; $data = $this->decode($data, $format); diff --git a/SerializerInterface.php b/SerializerInterface.php index 9a5184291..e4d83cdf5 100644 --- a/SerializerInterface.php +++ b/SerializerInterface.php @@ -27,7 +27,7 @@ interface SerializerInterface * * @return string */ - function serialize($data, $format, array $options = array()); + public function serialize($data, $format, array $options = array()); /** * Deserializes data into the given type. @@ -39,12 +39,12 @@ function serialize($data, $format, array $options = array()); * * @return object */ - function deserialize($data, $type, $format, array $options = array()); + public function deserialize($data, $type, $format, array $options = array()); /** * Get current options of the serializer * * @return array */ - function getOptions(); + public function getOptions(); } diff --git a/Tests/Encoder/XmlEncoderTest.php b/Tests/Encoder/XmlEncoderTest.php index aa0d03c7e..b23d4c793 100644 --- a/Tests/Encoder/XmlEncoderTest.php +++ b/Tests/Encoder/XmlEncoderTest.php @@ -188,7 +188,7 @@ public function testEncodeSerializerXmlRootNodeNameOption() { $options = array('xml_root_node_name' => 'test'); $this->encoder = new XmlEncoder; - $serializer = new Serializer(array(), array('xml' => new XmlEncoder()), $options); + $serializer = new Serializer(array(), array('xml' => new XmlEncoder())); $this->encoder->setSerializer($serializer); $array = array( @@ -198,7 +198,7 @@ public function testEncodeSerializerXmlRootNodeNameOption() $expected = ''."\n". 'Peter'."\n"; - $this->assertEquals($expected, $this->encoder->encode($array, 'xml')); + $this->assertEquals($expected, $serializer->serialize($array, 'xml', $options)); } public function testDecode()