浏览代码

minor performance tweak to reduce performance lost by previous commit

Lukas Kahwe Smith 14 年之前
父节点
当前提交
6212c5975e
共有 2 个文件被更改,包括 5 次插入2 次删除
  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()