Browse Source

minor performance tweak to reduce performance lost by previous commit

Lukas Kahwe Smith 14 years ago
parent
commit
6212c5975e
2 changed files with 5 additions and 2 deletions
  1. 1 1
      Serializer/Serializer.php
  2. 4 1
      Tests/Serializer/SerializerTest.php

+ 1 - 1
Serializer/Serializer.php

@@ -73,7 +73,7 @@ class Serializer implements SerializerInterface
      */
     public final function normalize($data, $format = null)
     {
-        if ($this->customObjectNormalizers) {
+        if (is_object($data) && $this->customObjectNormalizers) {
             foreach ($this->customObjectNormalizers as $normalizer) {
                 if ($normalizer->supportsNormalization($data, $format)) {
                     return $normalizer->normalize($data, $format);

+ 4 - 1
Tests/Serializer/SerializerTest.php

@@ -51,9 +51,12 @@ class SerializerTest extends \PHPUnit_Framework_TestCase
 
         $list = new AuthorList();
         $list->add(new Author('Bar'));
-        $normalized = $serializer->normalize($list);
 
+        $normalized = $serializer->normalize($list);
         $this->assertEquals(array(), $normalized);
+
+        $normalized = $serializer->normalize(array('foo'));
+        $this->assertEquals(array('foo'), $normalized);
     }
 
     public function testDenormalize()