@@ -27,18 +27,39 @@ public static function defaultResolveFn($source, $args, ResolveInfo $info)
27
27
$ fieldName = $ info ->fieldName ;
28
28
$ property = null ;
29
29
30
- if (null === self ::$ accessor ) {
31
- self ::$ accessor = PropertyAccess::createPropertyAccessor ();
32
- }
33
-
34
30
$ index = sprintf ('[%s] ' , $ fieldName );
35
31
36
- if (self ::$ accessor ->isReadable ($ source , $ index )) {
37
- $ property = self ::$ accessor ->getValue ($ source , $ index );
38
- } elseif (self :: $ accessor -> isReadable ($ source, $ fieldName )) {
39
- $ property = self ::$ accessor -> getValue ($ source , $ fieldName );
32
+ if (self ::getAccessor () ->isReadable ($ source , $ index )) {
33
+ $ property = self ::getAccessor () ->getValue ($ source , $ index );
34
+ } elseif (is_object ($ source )) {
35
+ $ property = self ::propertyValueFromObject ($ source , $ fieldName );
40
36
}
41
37
42
38
return $ property instanceof \Closure ? $ property ($ source , $ args , $ info ) : $ property ;
43
39
}
40
+
41
+ private static function propertyValueFromObject ($ object , $ fieldName )
42
+ {
43
+ $ property = null ;
44
+
45
+ // accessor try to access the value using methods
46
+ // first before using public property directly
47
+ // not what we wont here!
48
+ if (isset ($ object ->{$ fieldName })) {
49
+ $ property = $ object ->{$ fieldName };
50
+ } elseif (self ::getAccessor ()->isReadable ($ object , $ fieldName )) {
51
+ $ property = self ::getAccessor ()->getValue ($ object , $ fieldName );
52
+ }
53
+
54
+ return $ property ;
55
+ }
56
+
57
+ private static function getAccessor ()
58
+ {
59
+ if (null === self ::$ accessor ) {
60
+ self ::$ accessor = PropertyAccess::createPropertyAccessor ();
61
+ }
62
+
63
+ return self ::$ accessor ;
64
+ }
44
65
}
0 commit comments