1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Overblog\GraphQLBundle\Config; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
6
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
7
|
|
|
|
8
|
|
|
class ObjectTypeDefinition extends TypeWithOutputFieldsDefinition |
9
|
|
|
{ |
10
|
29 |
|
public function getDefinition() |
11
|
|
|
{ |
12
|
29 |
|
$builder = new TreeBuilder(); |
13
|
29 |
|
$node = $builder->root('_object_config'); |
14
|
|
|
|
15
|
|
|
$node |
|
|
|
|
16
|
29 |
|
->children() |
17
|
29 |
|
->append($this->nameSection()) |
18
|
29 |
|
->append($this->outputFieldsSelection()) |
19
|
29 |
|
->append($this->descriptionSection()) |
20
|
29 |
|
->arrayNode('interfaces') |
21
|
29 |
|
->prototype('scalar')->info('One of internal or custom interface types.')->end() |
22
|
29 |
|
->end() |
23
|
29 |
|
->variableNode('isTypeOf')->end() |
24
|
29 |
|
->variableNode('resolveField')->end() |
25
|
29 |
|
->variableNode('fieldsDefaultAccess') |
26
|
29 |
|
->info('Default access control to fields (expression language can be use here)') |
27
|
29 |
|
->end() |
28
|
29 |
|
->variableNode('fieldsDefaultPublic') |
29
|
29 |
|
->info('Default public control to fields (expression language can be use here)') |
30
|
29 |
|
->end() |
31
|
29 |
|
->end(); |
32
|
|
|
|
33
|
29 |
|
$this->treatFieldsDefaultAccess($node); |
34
|
29 |
|
$this->treatFieldsDefaultPublic($node); |
35
|
29 |
|
|
36
|
|
|
return $node; |
37
|
29 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* set empty fields.access with fieldsDefaultAccess values if is set? |
41
|
|
|
* |
42
|
|
|
* @param ArrayNodeDefinition $node |
43
|
|
|
*/ |
44
|
|
View Code Duplication |
private function treatFieldsDefaultAccess(ArrayNodeDefinition $node) |
|
|
|
|
45
|
29 |
|
{ |
46
|
|
|
$node->validate() |
47
|
29 |
|
->ifTrue(function ($v) { |
48
|
29 |
|
return array_key_exists('fieldsDefaultAccess', $v) && null !== $v['fieldsDefaultAccess']; |
49
|
24 |
|
}) |
50
|
29 |
|
->then(function ($v) { |
51
|
29 |
|
foreach ($v['fields'] as &$field) { |
52
|
1 |
|
if (array_key_exists('access', $field) && null !== $field['access']) { |
53
|
1 |
|
continue; |
54
|
1 |
|
} |
55
|
|
|
|
56
|
|
|
$field['access'] = $v['fieldsDefaultAccess']; |
57
|
1 |
|
} |
58
|
|
|
|
59
|
|
|
return $v; |
60
|
1 |
|
}) |
61
|
29 |
|
->end(); |
62
|
29 |
|
} |
63
|
29 |
|
|
64
|
|
|
/** |
65
|
|
|
* set empty fields.public with fieldsDefaultPublic values if is set? |
66
|
|
|
* |
67
|
|
|
* @param ArrayNodeDefinition $node |
68
|
|
|
*/ |
69
|
|
View Code Duplication |
private function treatFieldsDefaultPublic(ArrayNodeDefinition $node) |
|
|
|
|
70
|
29 |
|
{ |
71
|
|
|
$node->validate() |
72
|
29 |
|
->ifTrue(function ($v) { |
73
|
29 |
|
return array_key_exists('fieldsDefaultPublic', $v) && null !== $v['fieldsDefaultPublic']; |
74
|
24 |
|
}) |
75
|
29 |
|
->then(function ($v) { |
76
|
29 |
|
foreach ($v['fields'] as &$field) { |
77
|
1 |
|
if (array_key_exists('public', $field) && null !== $field['public']) { |
78
|
1 |
|
continue; |
79
|
1 |
|
} |
80
|
|
|
|
81
|
|
|
$field['public'] = $v['fieldsDefaultPublic']; |
82
|
1 |
|
} |
83
|
|
|
|
84
|
|
|
return $v; |
85
|
1 |
|
}) |
86
|
29 |
|
->end(); |
87
|
29 |
|
} |
88
|
|
|
} |
89
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.