Jelajahi Sumber

Allow to fetch data from has*() with public_method

Same as is*() method, has*() is mostly used with booleans
Nikolai Zujev 11 tahun lalu
induk
melakukan
0fb344a8ec
1 mengubah file dengan 3 tambahan dan 1 penghapusan
  1. 3 1
      src/JMS/Serializer/Metadata/PropertyMetadata.php

+ 3 - 1
src/JMS/Serializer/Metadata/PropertyMetadata.php

@@ -60,8 +60,10 @@ class PropertyMetadata extends BasePropertyMetadata
                     $getter = 'get'.$this->name;
                 } elseif ($class->hasMethod('is'.$this->name) && $class->getMethod('is'.$this->name)->isPublic()) {
                     $getter = 'is'.$this->name;
+                } elseif ($class->hasMethod('has'.$this->name) && $class->getMethod('has'.$this->name)->isPublic()) {
+                    $getter = 'has'.$this->name;
                 } else {
-                    throw new RuntimeException(sprintf('There is neither a public %s method, nor a public %s method in class %s. Please specify which public method should be used for retrieving the value of the property %s.', 'get'.ucfirst($this->name), 'is'.ucfirst($this->name), $this->class, $this->name));
+                    throw new RuntimeException(sprintf('There is neither a public %s method, nor a public %s method, nor a public %s method in class %s. Please specify which public method should be used for retrieving the value of the property %s.', 'get'.ucfirst($this->name), 'is'.ucfirst($this->name), 'has'.ucfirst($this->name), $this->class, $this->name));
                 }
             }