|
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
|
32 |
|
public function getDefinition() |
|
11
|
|
|
{ |
|
12
|
32 |
|
$builder = new TreeBuilder(); |
|
13
|
32 |
|
$node = $builder->root('_object_config'); |
|
14
|
|
|
|
|
15
|
|
|
$node |
|
|
|
|
|
|
16
|
32 |
|
->children() |
|
17
|
32 |
|
->append($this->nameSection()) |
|
18
|
32 |
|
->append($this->outputFieldsSelection()) |
|
19
|
32 |
|
->append($this->descriptionSection()) |
|
20
|
32 |
|
->arrayNode('interfaces') |
|
21
|
32 |
|
->prototype('scalar')->info('One of internal or custom interface types.')->end() |
|
22
|
32 |
|
->end() |
|
23
|
32 |
|
->variableNode('isTypeOf')->end() |
|
24
|
32 |
|
->variableNode('resolveField')->end() |
|
25
|
32 |
|
->variableNode('fieldsDefaultAccess') |
|
26
|
32 |
|
->info('Default access control to fields (expression language can be use here)') |
|
27
|
32 |
|
->end() |
|
28
|
32 |
|
->variableNode('fieldsDefaultPublic') |
|
29
|
32 |
|
->info('Default public control to fields (expression language can be use here)') |
|
30
|
32 |
|
->end() |
|
31
|
32 |
|
->end(); |
|
32
|
|
|
|
|
33
|
32 |
|
$this->treatFieldsDefaultAccess($node); |
|
34
|
32 |
|
$this->treatFieldsDefaultPublic($node); |
|
35
|
|
|
|
|
36
|
32 |
|
return $node; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* set empty fields.access with fieldsDefaultAccess values if is set? |
|
41
|
|
|
* |
|
42
|
|
|
* @param ArrayNodeDefinition $node |
|
43
|
|
|
*/ |
|
44
|
32 |
View Code Duplication |
private function treatFieldsDefaultAccess(ArrayNodeDefinition $node) |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
32 |
|
$node->validate() |
|
47
|
32 |
|
->ifTrue(function ($v) { |
|
48
|
27 |
|
return array_key_exists('fieldsDefaultAccess', $v) && null !== $v['fieldsDefaultAccess']; |
|
49
|
32 |
|
}) |
|
50
|
32 |
|
->then(function ($v) { |
|
51
|
1 |
|
foreach ($v['fields'] as &$field) { |
|
52
|
1 |
|
if (array_key_exists('access', $field) && null !== $field['access']) { |
|
53
|
1 |
|
continue; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
1 |
|
$field['access'] = $v['fieldsDefaultAccess']; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
return $v; |
|
60
|
32 |
|
}) |
|
61
|
32 |
|
->end(); |
|
62
|
32 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* set empty fields.public with fieldsDefaultPublic values if is set? |
|
66
|
|
|
* |
|
67
|
|
|
* @param ArrayNodeDefinition $node |
|
68
|
|
|
*/ |
|
69
|
32 |
View Code Duplication |
private function treatFieldsDefaultPublic(ArrayNodeDefinition $node) |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
32 |
|
$node->validate() |
|
72
|
32 |
|
->ifTrue(function ($v) { |
|
73
|
27 |
|
return array_key_exists('fieldsDefaultPublic', $v) && null !== $v['fieldsDefaultPublic']; |
|
74
|
32 |
|
}) |
|
75
|
32 |
|
->then(function ($v) { |
|
76
|
1 |
|
foreach ($v['fields'] as &$field) { |
|
77
|
1 |
|
if (array_key_exists('public', $field) && null !== $field['public']) { |
|
78
|
1 |
|
continue; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
1 |
|
$field['public'] = $v['fieldsDefaultPublic']; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
1 |
|
return $v; |
|
85
|
32 |
|
}) |
|
86
|
32 |
|
->end(); |
|
87
|
32 |
|
} |
|
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.