Browse Source

[Serializer] Inlined back the logic from isStructuredType and removed the method

Jordi Boggiano 14 years ago
parent
commit
4104c7b073

+ 0 - 3
src/Symfony/Component/Serializer/Encoder/JsonEncoder.php

@@ -25,9 +25,6 @@ class JsonEncoder extends AbstractEncoder implements DecoderInterface
      */
     public function encode($data, $format)
     {
-        if ($this->serializer->isStructuredType($data)) {
-            $data = $this->serializer->normalize($data, $format);
-        }
         return json_encode($data);
     }
 

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

@@ -38,7 +38,7 @@ class XmlEncoder extends AbstractEncoder implements DecoderInterface
         $this->dom = new \DOMDocument();
         $this->format = $format;
 
-        if ($this->serializer->isStructuredType($data)) {
+        if (null !== $data && !is_scalar($data)) {
             $root = $this->dom->createElement($this->rootNodeName);
             $this->dom->appendChild($root);
             $this->buildXml($root, $data);
@@ -248,16 +248,16 @@ class XmlEncoder extends AbstractEncoder implements DecoderInterface
         }
         if (is_object($data)) {
             $data = $this->serializer->normalizeObject($data, $this->format);
-            if (!$this->serializer->isStructuredType($data)) {
-                // top level data object is normalized into a scalar
-                if (!$parentNode->parentNode->parentNode) {
-                    $root = $parentNode->parentNode;
-                    $root->removeChild($parentNode);
-                    return $this->appendNode($root, $data, $this->rootNodeName);
-                }
-                return $this->appendNode($parentNode, $data, 'data');
+            if (null !== $data && !is_scalar($data)) {
+                return $this->buildXml($parentNode, $data);
+            }
+            // 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->rootNodeName);
             }
-            return $this->buildXml($parentNode, $data);
+            return $this->appendNode($parentNode, $data, 'data');
         }
         throw new \UnexpectedValueException('An unexpected value could not be serialized: '.var_export($data, true));
     }

+ 1 - 1
src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php

@@ -52,7 +52,7 @@ class GetSetMethodNormalizer extends AbstractNormalizer
 
                 if (null === $propertyMap || isset($propertyMap[$attributeName])) {
                     $attributeValue = $method->invoke($object);
-                    if ($this->serializer->isStructuredType($attributeValue)) {
+                    if (null !== $attributeValue && !is_scalar($attributeValue)) {
                         $attributeValue = $this->serializer->normalize($attributeValue, $format);
                     }
 

+ 1 - 10
src/Symfony/Component/Serializer/Serializer.php

@@ -34,15 +34,6 @@ class Serializer implements SerializerInterface
     protected $normalizerCache = array();
     protected $denormalizerCache = array();
 
-    /**
-     * @param mixed $value value to test
-     * @return Boolean whether the type is a structured type (array + objects)
-     */
-    public function isStructuredType($value)
-    {
-        return null !== $value && !is_scalar($value);
-    }
-
     /**
      * {@inheritdoc}
      */
@@ -104,7 +95,7 @@ class Serializer implements SerializerInterface
      */
     public function normalize($data, $format = null)
     {
-        if (!$this->isStructuredType($data)) {
+        if (null === $value || is_scalar($value)) {
             return $data;
         }
         if ($data instanceof Traversable) {