瀏覽代碼

use isset instead of in_array

Christian Stocker 13 年之前
父節點
當前提交
22bb827fd1
共有 1 個文件被更改,包括 11 次插入10 次删除
  1. 11 10
      Serializer/Exclusion/GroupExclusionStrategy.php

+ 11 - 10
Serializer/Exclusion/GroupExclusionStrategy.php

@@ -23,14 +23,17 @@ use JMS\SerializerBundle\Metadata\PropertyMetadata;
 
 
 class GroupExclusionStrategy implements ExclusionStrategyInterface
 class GroupExclusionStrategy implements ExclusionStrategyInterface
 {
 {
-    private $group;
+    private $groups = array();
 
 
-    public function __construct($group)
+    public function __construct($groups)
     {
     {
-        if (!is_array($group)) {
-            $group = array($group);
+        if (!is_array($groups)) {
+            $this->groups[$groups] = true;
+        } else {
+            foreach ($groups as $group) {
+                $this->groups[$group] = true;
+            }
         }
         }
-        $this->group = $group;
     }
     }
 
 
     public function shouldSkipClass(ClassMetadata $metadata)
     public function shouldSkipClass(ClassMetadata $metadata)
@@ -43,15 +46,13 @@ class GroupExclusionStrategy implements ExclusionStrategyInterface
      */
      */
     public function shouldSkipProperty(PropertyMetadata $property)
     public function shouldSkipProperty(PropertyMetadata $property)
     {
     {
-        if ($this->group && $property->group) {
-            foreach($this->group as $group) {
-                if (in_array($group, $property->group)) {
+        if ($this->groups && $property->group) {
+            foreach ($property->group as $group) {
+                if (isset($this->groups[$group])) {
                     return false;
                     return false;
                 }
                 }
             }
             }
         }
         }
-            
         return true;
         return true;
-        
     }
     }
 }
 }