فهرست منبع

readonly flag should be set before setter, because the setter depends on that being set

Miha Vrhovnik 12 سال پیش
والد
کامیت
e720a61eb0
4فایلهای تغییر یافته به همراه15 افزوده شده و 8 حذف شده
  1. 3 2
      Metadata/Driver/AnnotationDriver.php
  2. 5 3
      Metadata/Driver/XmlDriver.php
  3. 5 3
      Metadata/Driver/YamlDriver.php
  4. 2 0
      Tests/Fixtures/AuthorReadOnly.php

+ 3 - 2
Metadata/Driver/AnnotationDriver.php

@@ -159,14 +159,15 @@ class AnnotationDriver implements DriverInterface
                         $propertyMetadata->xmlValue = true;
                     } else if ($annot instanceof AccessType) {
                         $AccessType = $annot->type;
+                    //we need ReadOnly before setter and getter set, because that method depends on flag being set
+                    } else if ($annot instanceof ReadOnly) {
+                       $propertyMetadata->readOnly = true;
                     } else if ($annot instanceof Accessor) {
                         $accessor = array($annot->getter, $annot->setter);
                     } else if ($annot instanceof Groups) {
                         $propertyMetadata->groups = $annot->groups;
                     } else if ($annot instanceof Inline) {
                         $propertyMetadata->inline = true;
-                    } else if ($annot instanceof ReadOnly) {
-                        $propertyMetadata->readOnly = true;
                     }
                 }
 

+ 5 - 3
Metadata/Driver/XmlDriver.php

@@ -166,6 +166,11 @@ class XmlDriver extends AbstractFileDriver
                         $pMetadata->xmlKeyValuePairs = 'true' === (string) $pElem->attributes()->{'xml-key-value-pairs'};
                     }
 
+                    //we need read-only before setter and getter set, because that method depends on flag being set
+                    if (null !== $readOnly = $pElem->attributes()->{'read-only'}) {
+                        //$pMetadata->readOnly = 'true' === strtolower($readOnly);
+                    }
+
                     $getter = $pElem->attributes()->{'accessor-getter'};
                     $setter = $pElem->attributes()->{'accessor-setter'};
                     $pMetadata->setAccessor(
@@ -178,9 +183,6 @@ class XmlDriver extends AbstractFileDriver
                         $pMetadata->inline = 'true' === strtolower($inline);
                     }
 
-                    if (null !== $readOnly = $pElem->attributes()->{'read-only'}) {
-                        $pMetadata->readOnly = 'true' === strtolower($readOnly);
-                    }
                 }
 
                 if ((ExclusionPolicy::NONE === (string)$exclusionPolicy && !$isExclude)

+ 5 - 3
Metadata/Driver/YamlDriver.php

@@ -156,6 +156,11 @@ class YamlDriver extends AbstractFileDriver
                         $pMetadata->xmlKeyValuePairs = (Boolean) $pConfig['xml_key_value_pairs'];
                     }
 
+                    //we need read_only before setter and getter set, because that method depends on flag being set
+                    if (isset($pConfig['read_only'])) {
+                          $pMetadata->readOnly = (Boolean) $pConfig['read_only'];
+                    }
+
                     $pMetadata->setAccessor(
                         isset($pConfig['access_type']) ? $pConfig['access_type'] : $classAccessType,
                         isset($pConfig['accessor']) ? $pConfig['accessor'] : null
@@ -165,9 +170,6 @@ class YamlDriver extends AbstractFileDriver
                         $pMetadata->inline = (Boolean) $pConfig['inline'];
                     }
 
-                    if (isset($pConfig['read_only'])) {
-                        $pMetadata->readOnly = (Boolean) $pConfig['read_only'];
-                    }
                 }
                 if ((ExclusionPolicy::NONE === $exclusionPolicy && !$isExclude)
                 || (ExclusionPolicy::ALL === $exclusionPolicy && $isExpose)) {

+ 2 - 0
Tests/Fixtures/AuthorReadOnly.php

@@ -22,6 +22,7 @@ use JMS\SerializerBundle\Annotation\SerializedName;
 use JMS\SerializerBundle\Annotation\Type;
 use JMS\SerializerBundle\Annotation\XmlRoot;
 use JMS\SerializerBundle\Annotation\ReadOnly;
+use JMS\SerializerBundle\Annotation\Accessor;
 
 /** @XmlRoot("author") */
 class AuthorReadOnly
@@ -35,6 +36,7 @@ class AuthorReadOnly
     /**
      * @Type("string")
      * @SerializedName("full_name")
+     * @Accessor("getName")
      */
     private $name;