Pārlūkot izejas kodu

use isset instead of in_array

Christian Stocker 13 gadi atpakaļ
vecāks
revīzija
22bb827fd1
1 mainītis faili ar 11 papildinājumiem un 10 dzēšanām
  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
 {
-    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)
@@ -43,15 +46,13 @@ class GroupExclusionStrategy implements ExclusionStrategyInterface
      */
     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 true;
-        
     }
 }