瀏覽代碼

made (de)normalizeObject() private

Lukas Kahwe Smith 14 年之前
父節點
當前提交
1eecf1a5d1

+ 2 - 2
src/Symfony/Component/Serializer/Encoder/XmlEncoder.php

@@ -254,7 +254,7 @@ class XmlEncoder extends SerializerAwareEncoder implements DecoderInterface, Nor
             return $append;
         }
         if (is_object($data)) {
-            $data = $this->serializer->normalizeObject($data, $this->format);
+            $data = $this->serializer->normalize($data, $this->format);
             if (null !== $data && !is_scalar($data)) {
                 return $this->buildXml($parentNode, $data);
             }
@@ -312,7 +312,7 @@ class XmlEncoder extends SerializerAwareEncoder implements DecoderInterface, Nor
         } elseif ($val instanceof \Traversable) {
             $this->buildXml($node, $val);
         } elseif (is_object($val)) {
-            return $this->buildXml($node, $this->serializer->normalizeObject($val, $this->format));
+            return $this->buildXml($node, $this->serializer->normalize($val, $this->format));
         } elseif (is_numeric($val)) {
             return $this->appendText($node, (string) $val);
         } elseif (is_string($val)) {

+ 13 - 4
src/Symfony/Component/Serializer/Serializer.php

@@ -119,9 +119,13 @@ class Serializer implements SerializerInterface
     }
 
     /**
-     * {@inheritdoc}
+     * Normalizes an object into a set of arrays/scalars
+     *
+     * @param object $object object to normalize
+     * @param string $format format name, present to give the option to normalizers to act differently based on formats
+     * @return array|scalar
      */
-    public function normalizeObject($object, $format = null)
+    private function normalizeObject($object, $format = null)
     {
         if (!$this->normalizers) {
             throw new \LogicException('You must register at least one normalizer to be able to normalize objects.');
@@ -141,9 +145,14 @@ class Serializer implements SerializerInterface
     }
 
     /**
-     * {@inheritdoc}
+     * Denormalizes data back into an object of the given class
+     *
+     * @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
+     * @return object
      */
-    public function denormalizeObject($data, $class, $format = null)
+    private function denormalizeObject($data, $class, $format = null)
     {
         if (!$this->normalizers) {
             throw new \LogicException('You must register at least one normalizer to be able to denormalize objects.');

+ 15 - 34
src/Symfony/Component/Serializer/SerializerInterface.php

@@ -84,33 +84,25 @@ interface SerializerInterface
     function decode($data, $format);
 
     /**
-     * Normalizes an object into a set of arrays/scalars
+     * Checks whether the serializer can serialize the given 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
-     * @return array|scalar
+     * @param string $format format name
+     * @return Boolean
      */
-    function normalizeObject($object, $format = null);
+    function supportsSerialization($format);
 
     /**
-     * Denormalizes data back into an object of the given class
+     * Checks whether the serializer can deserialize the given format
      *
-     * @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
-     * @return object
-     */
-    function denormalizeObject($data, $class, $format = null);
-
-    /**
-     * @param NormalizerInterface $normalizer
+     * @param string $format format name
+     * @return Boolean
      */
-    function addNormalizer(NormalizerInterface $normalizer);
+    function supportsDeserialization($format);
 
     /**
-     * @param NormalizerInterface $normalizer
+     * @return EncoderInterface
      */
-    function removeNormalizer(NormalizerInterface $normalizer);
+    function getEncoder($format);
 
     /**
      * @param string           $format  format name
@@ -119,28 +111,17 @@ interface SerializerInterface
     function setEncoder($format, EncoderInterface $encoder);
 
     /**
-     * @return EncoderInterface
-     */
-    function getEncoder($format);
-
-    /**
-     * Checks whether the serializer can serialize the given format
-     *
      * @param string $format format name
-     * @return Boolean
      */
-    function supportsSerialization($format);
+    function removeEncoder($format);
 
     /**
-     * Checks whether the serializer can deserialize the given format
-     *
-     * @param string $format format name
-     * @return Boolean
+     * @param NormalizerInterface $normalizer
      */
-    function supportsDeserialization($format);
+    function addNormalizer(NormalizerInterface $normalizer);
 
     /**
-     * @param string $format format name
+     * @param NormalizerInterface $normalizer
      */
-    function removeEncoder($format);
+    function removeNormalizer(NormalizerInterface $normalizer);
 }