1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Overblog\GraphQLBundle\Config; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
8
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
9
|
|
|
|
10
|
|
|
abstract class TypeWithOutputFieldsDefinition extends TypeDefinition |
11
|
|
|
{ |
12
|
47 |
|
protected function outputFieldsSection(): NodeDefinition |
13
|
|
|
{ |
14
|
47 |
|
$node = self::createNode('fields'); |
15
|
|
|
$node |
16
|
47 |
|
->isRequired() |
17
|
47 |
|
->requiresAtLeastOneElement(); |
|
|
|
|
18
|
|
|
|
19
|
|
|
/* @var ArrayNodeDefinition $prototype */ |
20
|
47 |
|
$prototype = $node->useAttributeAsKey('name', false)->prototype('array'); |
|
|
|
|
21
|
|
|
|
22
|
|
|
$prototype |
23
|
47 |
|
->beforeNormalization() |
24
|
|
|
// Allow field type short syntax (Field: Type => Field: {type: Type}) |
25
|
47 |
|
->ifTrue(fn ($options) => \is_string($options)) |
26
|
47 |
|
->then(fn ($options) => ['type' => $options]) |
27
|
47 |
|
->end() |
28
|
47 |
|
->validate() |
29
|
|
|
// Remove empty entries |
30
|
|
|
->always(function ($value) { |
31
|
37 |
|
if (empty($value['validationGroups'])) { |
32
|
37 |
|
unset($value['validationGroups']); |
33
|
|
|
} |
34
|
|
|
|
35
|
37 |
|
if (empty($value['args'])) { |
36
|
37 |
|
unset($value['args']); |
37
|
|
|
} |
38
|
|
|
|
39
|
37 |
|
return $value; |
40
|
47 |
|
}) |
41
|
47 |
|
->end() |
42
|
47 |
|
->children() |
43
|
47 |
|
->append($this->typeSection()) |
44
|
47 |
|
->append($this->validationSection(self::VALIDATION_LEVEL_CLASS)) |
45
|
47 |
|
->arrayNode('validationGroups') |
46
|
47 |
|
->beforeNormalization() |
47
|
47 |
|
->castToArray() |
48
|
47 |
|
->end() |
49
|
47 |
|
->prototype('scalar') |
50
|
47 |
|
->info('List of validation groups') |
51
|
47 |
|
->end() |
52
|
47 |
|
->end() |
53
|
47 |
|
->arrayNode('args') |
54
|
47 |
|
->info('Array of possible type arguments. Each entry is expected to be an array with following keys: name (string), type') |
55
|
47 |
|
->useAttributeAsKey('name', false) |
56
|
47 |
|
->prototype('array') |
57
|
|
|
// Allow arg type short syntax (Arg: Type => Arg: {type: Type}) |
58
|
47 |
|
->beforeNormalization() |
59
|
47 |
|
->ifTrue(fn ($options) => \is_string($options)) |
60
|
47 |
|
->then(fn ($options) => ['type' => $options]) |
61
|
47 |
|
->end() |
62
|
47 |
|
->children() |
63
|
47 |
|
->append($this->typeSection(true)) |
64
|
47 |
|
->append($this->descriptionSection()) |
65
|
47 |
|
->append($this->defaultValueSection()) |
66
|
47 |
|
->append($this->validationSection(self::VALIDATION_LEVEL_PROPERTY)) |
67
|
47 |
|
->end() |
68
|
47 |
|
->end() |
69
|
47 |
|
->end() |
70
|
47 |
|
->variableNode('resolve') |
71
|
47 |
|
->info('Value resolver (expression language can be used here)') |
72
|
47 |
|
->end() |
73
|
47 |
|
->append($this->descriptionSection()) |
74
|
47 |
|
->append($this->deprecationReasonSection()) |
75
|
47 |
|
->variableNode('access') |
76
|
47 |
|
->info('Access control to field (expression language can be used here)') |
77
|
47 |
|
->end() |
78
|
47 |
|
->variableNode('public') |
79
|
47 |
|
->info('Visibility control to field (expression language can be used here)') |
80
|
47 |
|
->end() |
81
|
47 |
|
->variableNode('complexity') |
82
|
47 |
|
->info('Custom complexity calculator.') |
83
|
47 |
|
->end() |
84
|
47 |
|
->end(); |
85
|
|
|
|
86
|
47 |
|
return $node; |
87
|
|
|
} |
88
|
|
|
|
89
|
47 |
|
protected function fieldsBuilderSection() |
90
|
|
|
{ |
91
|
47 |
|
$node = self::createNode('builders'); |
92
|
|
|
|
93
|
47 |
|
$prototype = $node->prototype('array'); |
94
|
|
|
|
95
|
|
|
$prototype |
96
|
47 |
|
->children() |
97
|
47 |
|
->variableNode('builder')->isRequired()->end() |
98
|
47 |
|
->variableNode('builderConfig')->end() |
99
|
47 |
|
->end(); |
100
|
|
|
|
101
|
47 |
|
return $node; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|