浏览代码

Allow to fetch data from has*() with public_method

Same as is*() method, has*() is mostly used with booleans
Nikolai Zujev 11 年之前
父节点
当前提交
0fb344a8ec
共有 1 个文件被更改,包括 3 次插入1 次删除
  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));
                 }
             }