@@ -35,25 +35,30 @@ class GetterMetadata extends MemberMetadata
35
35
/**
36
36
* Constructor.
37
37
*
38
- * @param string $class The class the getter is defined on
39
- * @param string $property The property which the getter returns
38
+ * @param string $class The class the getter is defined on
39
+ * @param string $property The property which the getter returns
40
+ * @param string|null $method The method that is called to retrieve the value being validated (null for auto-detection)
40
41
*
41
42
* @throws ValidatorException
42
43
*/
43
- public function __construct ($ class , $ property )
44
+ public function __construct ($ class , $ property, $ method = null )
44
45
{
45
- $ getMethod = 'get ' .ucfirst ($ property );
46
- $ isMethod = 'is ' .ucfirst ($ property );
47
- $ hasMethod = 'has ' .ucfirst ($ property );
46
+ if (null === $ method ) {
47
+ $ getMethod = 'get ' .ucfirst ($ property );
48
+ $ isMethod = 'is ' .ucfirst ($ property );
49
+ $ hasMethod = 'has ' .ucfirst ($ property );
48
50
49
- if (method_exists ($ class , $ getMethod )) {
50
- $ method = $ getMethod ;
51
- } elseif (method_exists ($ class , $ isMethod )) {
52
- $ method = $ isMethod ;
53
- } elseif (method_exists ($ class , $ hasMethod )) {
54
- $ method = $ hasMethod ;
55
- } else {
56
- throw new ValidatorException (sprintf ('Neither of these methods exist in class %s: %s, %s, %s ' , $ class , $ getMethod , $ isMethod , $ hasMethod ));
51
+ if (method_exists ($ class , $ getMethod )) {
52
+ $ method = $ getMethod ;
53
+ } elseif (method_exists ($ class , $ isMethod )) {
54
+ $ method = $ isMethod ;
55
+ } elseif (method_exists ($ class , $ hasMethod )) {
56
+ $ method = $ hasMethod ;
57
+ } else {
58
+ throw new ValidatorException (sprintf ('Neither of these methods exist in class %s: %s, %s, %s ' , $ class , $ getMethod , $ isMethod , $ hasMethod ));
59
+ }
60
+ } elseif (!method_exists ($ class , $ method )) {
61
+ throw new ValidatorException (sprintf ('The %s() method does not exist in class %s. ' , $ method , $ class ));
57
62
}
58
63
59
64
parent ::__construct ($ class , $ method , $ property );
0 commit comments