1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ApiSkeletons\Doctrine\GraphQL; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* This class is used for setting parameters when |
9
|
|
|
* creating the driver |
10
|
|
|
*/ |
11
|
|
|
class Config |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string The GraphQL group. This allows multiple GraphQL |
15
|
|
|
* configurations within the same application or |
16
|
|
|
* even within the same group of entities and Object Manager. |
17
|
|
|
*/ |
18
|
|
|
protected string $group = 'default'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string|null The group is usually suffixed to GraphQL type names. |
22
|
|
|
* You may specify a different string for the group suffix |
23
|
|
|
* or you my supply an empty string to exclude the suffix. |
24
|
|
|
* Be warned, using the same groupSuffix with two different |
25
|
|
|
* groups can cause collisions. |
26
|
|
|
*/ |
27
|
|
|
protected string|null $groupSuffix = null; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var bool When set to true hydrator results will be cached for the |
31
|
|
|
* duration of the request thereby saving multiple extracts for |
32
|
|
|
* the same entity. |
33
|
|
|
*/ |
34
|
|
|
protected bool $useHydratorCache = false; |
35
|
|
|
|
36
|
|
|
/** @var int A hard limit for fetching any collection within the schema */ |
37
|
|
|
protected int $limit = 1000; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var bool When set to true all fields and all associations will be |
41
|
|
|
* enabled. This is best used as a development setting when |
42
|
|
|
* the entities are subject to change. |
43
|
|
|
*/ |
44
|
|
|
protected bool $globalEnable = false; |
45
|
|
|
|
46
|
|
|
/** @var string[] An array if field names to ignore when using globalEnable. */ |
47
|
|
|
protected array $globalIgnore = []; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var bool|null When set to true, all entities will be extracted by value |
51
|
|
|
* across all hydrators in the driver. When set to false, |
52
|
|
|
* all hydrators will extract by reference. This overrides |
53
|
|
|
* per-entity attribute configuration. |
54
|
|
|
*/ |
55
|
|
|
protected bool|null $globalByValue = null; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string|null When set, the entityPrefix will be removed from each |
59
|
|
|
* type name. This simplifies type names and makes reading |
60
|
|
|
* the GraphQL documentation easier. |
61
|
|
|
*/ |
62
|
|
|
protected string|null $entityPrefix = null; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var bool|null When set to true entity fields will be |
66
|
|
|
* sorted alphabetically |
67
|
|
|
*/ |
68
|
|
|
protected bool|null $sortFields = null; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var string[] An array of filters to exclude from |
72
|
|
|
* available filters for all fields and |
73
|
|
|
* associations in every entity |
74
|
|
|
*/ |
75
|
|
|
protected array $excludeCriteria = []; |
76
|
|
|
|
77
|
|
|
/** @param mixed[] $config */ |
78
|
|
|
public function __construct(array $config = []) |
79
|
|
|
{ |
80
|
|
|
/** |
81
|
|
|
* Dynamic setters will fail for invalid settings and allow for |
82
|
|
|
* validation of field types through setters |
83
|
|
|
*/ |
84
|
|
|
foreach ($config as $setting => $value) { |
85
|
|
|
$setter = 'set' . $setting; |
86
|
|
|
$this->$setter($value); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
protected function setGroup(string $group): self |
91
|
|
|
{ |
92
|
|
|
$this->group = $group; |
93
|
|
|
|
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function getGroup(): string |
98
|
|
|
{ |
99
|
|
|
return $this->group; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
protected function setGroupSuffix(string|null $groupSuffix): self |
103
|
|
|
{ |
104
|
|
|
$this->groupSuffix = $groupSuffix; |
105
|
|
|
|
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function getGroupSuffix(): string|null |
110
|
|
|
{ |
111
|
|
|
return $this->groupSuffix; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
protected function setUseHydratorCache(bool $useHydratorCache): self |
115
|
|
|
{ |
116
|
|
|
$this->useHydratorCache = $useHydratorCache; |
117
|
|
|
|
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function getUseHydratorCache(): bool |
122
|
|
|
{ |
123
|
|
|
return $this->useHydratorCache; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
protected function setLimit(int $limit): self |
127
|
|
|
{ |
128
|
|
|
$this->limit = $limit; |
129
|
|
|
|
130
|
|
|
return $this; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function getLimit(): int |
134
|
|
|
{ |
135
|
|
|
return $this->limit; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
protected function setGlobalEnable(bool $globalEnable): self |
139
|
|
|
{ |
140
|
|
|
$this->globalEnable = $globalEnable; |
141
|
|
|
|
142
|
|
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function getGlobalEnable(): bool |
146
|
|
|
{ |
147
|
|
|
return $this->globalEnable; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** @param string[] $globalIgnore */ |
151
|
|
|
protected function setGlobalIgnore(array $globalIgnore): self |
152
|
|
|
{ |
153
|
|
|
$this->globalIgnore = $globalIgnore; |
154
|
|
|
|
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** @return string[] */ |
159
|
|
|
public function getGlobalIgnore(): array |
160
|
|
|
{ |
161
|
|
|
return $this->globalIgnore; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
protected function setGlobalByValue(bool|null $globalByValue): self |
165
|
|
|
{ |
166
|
|
|
$this->globalByValue = $globalByValue; |
167
|
|
|
|
168
|
|
|
return $this; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function getGlobalByValue(): bool|null |
172
|
|
|
{ |
173
|
|
|
return $this->globalByValue; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
protected function setEntityPrefix(string|null $entityPrefix): self |
177
|
|
|
{ |
178
|
|
|
$this->entityPrefix = $entityPrefix; |
179
|
|
|
|
180
|
|
|
return $this; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function getEntityPrefix(): string|null |
184
|
|
|
{ |
185
|
|
|
return $this->entityPrefix; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function setSortFields(bool|null $sortFields): self |
189
|
|
|
{ |
190
|
|
|
$this->sortFields = $sortFields; |
191
|
|
|
|
192
|
|
|
return $this; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
public function getSortFields(): bool|null |
196
|
|
|
{ |
197
|
|
|
return $this->sortFields; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** @param string[] $excludeCriteria */ |
201
|
|
|
public function setExcludeCriteria(array $excludeCriteria): self |
202
|
|
|
{ |
203
|
|
|
$this->excludeCriteria = $excludeCriteria; |
204
|
|
|
|
205
|
|
|
return $this; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** @return string[] */ |
209
|
|
|
public function getExcludeCriteria(): array |
210
|
|
|
{ |
211
|
|
|
return $this->excludeCriteria; |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
|