1 | <?php |
||
17 | class DefaultFieldResolver |
||
18 | { |
||
19 | 12 | public function __invoke($source, $args, $context, ResolveInfo $info) |
|
32 | |||
33 | /** |
||
34 | * Resolve for an object |
||
35 | * @param mixed $source |
||
36 | * @param mixed $args |
||
37 | * @param string $fieldName |
||
38 | * @return mixed |
||
39 | */ |
||
40 | 11 | private function resolveObject($source, ?array $args, string $fieldName) |
|
53 | |||
54 | /** |
||
55 | * Resolve for an array |
||
56 | * @param mixed $source |
||
57 | * @param string $fieldName |
||
58 | * @return mixed |
||
59 | */ |
||
60 | 1 | private function resolveArray($source, string $fieldName) |
|
64 | |||
65 | /** |
||
66 | * Return the getter/isser method if any valid one exists |
||
67 | * @param mixed $source |
||
68 | * @param string $name |
||
69 | * @return string |
||
70 | */ |
||
71 | 11 | private function getGetter($source, string $name): ?ReflectionMethod |
|
72 | { |
||
73 | 11 | $class = new ReflectionClass($source); |
|
74 | |||
75 | 11 | if (!preg_match('~^(is|has)[A-Z]~', $name) || !$class->hasMethod($name)) |
|
76 | 9 | $name = 'get' . ucfirst($name); |
|
77 | |||
78 | 11 | if ($class->hasMethod($name)) { |
|
79 | 6 | $method = $class->getMethod($name); |
|
80 | 6 | if ($method->getModifiers() & ReflectionMethod::IS_PUBLIC) { |
|
81 | 4 | return $method; |
|
82 | } |
||
83 | } |
||
84 | |||
85 | 7 | return null; |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * Re-order associative args to ordered args |
||
90 | * @param ReflectionMethod $method |
||
91 | * @param array $args |
||
92 | * @return array |
||
93 | */ |
||
94 | 4 | private function orderArguments(ReflectionMethod $method, ?array $args): array |
|
105 | } |
||
106 |