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