Browse Source

Pass null for shouldSkipClass/shouldSkipProperty when deserializing

Jordi Boggiano 12 năm trước cách đây
mục cha
commit
14d4018c81

+ 4 - 4
Serializer/Exclusion/ExclusionStrategyInterface.php

@@ -32,19 +32,19 @@ interface ExclusionStrategyInterface
      * Whether the class should be skipped.
      *
      * @param ClassMetadata $metadata
-     * @param object        $object
+     * @param object        $object instance, provided during serialization but not deserialization
      *
      * @return boolean
      */
-    function shouldSkipClass(ClassMetadata $metadata, $object);
+    function shouldSkipClass(ClassMetadata $metadata, $object = null);
 
     /**
      * Whether the property should be skipped.
      *
      * @param PropertyMetadata $property
-     * @param object           $object
+     * @param object           $object instance, provided during serialization but not deserialization
      *
      * @return boolean
      */
-    function shouldSkipProperty(PropertyMetadata $property, $object);
+    function shouldSkipProperty(PropertyMetadata $property, $object = null);
 }

+ 2 - 2
Serializer/Exclusion/GroupsExclusionStrategy.php

@@ -37,7 +37,7 @@ class GroupsExclusionStrategy implements ExclusionStrategyInterface
         }
     }
 
-    public function shouldSkipClass(ClassMetadata $metadata, $object)
+    public function shouldSkipClass(ClassMetadata $metadata, $object = null)
     {
         return false;
     }
@@ -45,7 +45,7 @@ class GroupsExclusionStrategy implements ExclusionStrategyInterface
     /**
      * {@inheritDoc}
      */
-    public function shouldSkipProperty(PropertyMetadata $property, $object)
+    public function shouldSkipProperty(PropertyMetadata $property, $object = null)
     {
         if (!$property->groups) {
             return true;

+ 2 - 2
Serializer/Exclusion/VersionExclusionStrategy.php

@@ -30,7 +30,7 @@ class VersionExclusionStrategy implements ExclusionStrategyInterface
         $this->version = $version;
     }
 
-    public function shouldSkipClass(ClassMetadata $metadata, $object)
+    public function shouldSkipClass(ClassMetadata $metadata, $object = null)
     {
         return false;
     }
@@ -38,7 +38,7 @@ class VersionExclusionStrategy implements ExclusionStrategyInterface
     /**
      * {@inheritDoc}
      */
-    public function shouldSkipProperty(PropertyMetadata $property, $object)
+    public function shouldSkipProperty(PropertyMetadata $property, $object = null)
     {
         if ((null !== $version = $property->sinceVersion) && version_compare($this->version, $version, '<')) {
             return true;

+ 2 - 2
Serializer/GraphNavigator.php

@@ -97,7 +97,7 @@ final class GraphNavigator
             }
 
             $metadata = $this->metadataFactory->getMetadataForClass($type);
-            if (null !== $this->exclusionStrategy && $this->exclusionStrategy->shouldSkipClass($metadata, $data)) {
+            if (null !== $this->exclusionStrategy && $this->exclusionStrategy->shouldSkipClass($metadata, self::DIRECTION_SERIALIZATION === $this->direction ? $data : null)) {
                 if (self::DIRECTION_SERIALIZATION === $this->direction) {
                     $this->visiting->detach($data);
                 }
@@ -122,7 +122,7 @@ final class GraphNavigator
 
             $visitor->startVisitingObject($metadata, $data, $type);
             foreach ($metadata->propertyMetadata as $propertyMetadata) {
-                if (null !== $this->exclusionStrategy && $this->exclusionStrategy->shouldSkipProperty($propertyMetadata, $data)) {
+                if (null !== $this->exclusionStrategy && $this->exclusionStrategy->shouldSkipProperty($propertyMetadata, self::DIRECTION_SERIALIZATION === $this->direction ? $data : null)) {
                     continue;
                 }