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
|
|
|
/** @param mixed[] $config */ |
71
|
|
|
public function __construct(array $config = []) |
72
|
|
|
{ |
73
|
|
|
/** |
74
|
|
|
* Dynamic setters will fail for invalid settings and allow for |
75
|
|
|
* validation of field types through setters |
76
|
|
|
*/ |
77
|
|
|
foreach ($config as $setting => $value) { |
78
|
|
|
$setter = 'set' . $setting; |
79
|
|
|
$this->$setter($value); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
protected function setGroup(string $group): self |
84
|
|
|
{ |
85
|
|
|
$this->group = $group; |
86
|
|
|
|
87
|
|
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getGroup(): string |
91
|
|
|
{ |
92
|
|
|
return $this->group; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
protected function setGroupSuffix(string|null $groupSuffix): self |
96
|
|
|
{ |
97
|
|
|
$this->groupSuffix = $groupSuffix; |
98
|
|
|
|
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function getGroupSuffix(): string|null |
103
|
|
|
{ |
104
|
|
|
return $this->groupSuffix; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
protected function setUseHydratorCache(bool $useHydratorCache): self |
108
|
|
|
{ |
109
|
|
|
$this->useHydratorCache = $useHydratorCache; |
110
|
|
|
|
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function getUseHydratorCache(): bool |
115
|
|
|
{ |
116
|
|
|
return $this->useHydratorCache; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
protected function setLimit(int $limit): self |
120
|
|
|
{ |
121
|
|
|
$this->limit = $limit; |
122
|
|
|
|
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function getLimit(): int |
127
|
|
|
{ |
128
|
|
|
return $this->limit; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
protected function setGlobalEnable(bool $globalEnable): self |
132
|
|
|
{ |
133
|
|
|
$this->globalEnable = $globalEnable; |
134
|
|
|
|
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function getGlobalEnable(): bool |
139
|
|
|
{ |
140
|
|
|
return $this->globalEnable; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** @param string[] $globalIgnore */ |
144
|
|
|
protected function setGlobalIgnore(array $globalIgnore): self |
145
|
|
|
{ |
146
|
|
|
$this->globalIgnore = $globalIgnore; |
147
|
|
|
|
148
|
|
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** @return string[] */ |
152
|
|
|
public function getGlobalIgnore(): array |
153
|
|
|
{ |
154
|
|
|
return $this->globalIgnore; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
protected function setGlobalByValue(bool|null $globalByValue): self |
158
|
|
|
{ |
159
|
|
|
$this->globalByValue = $globalByValue; |
160
|
|
|
|
161
|
|
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function getGlobalByValue(): bool|null |
165
|
|
|
{ |
166
|
|
|
return $this->globalByValue; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
protected function setEntityPrefix(string|null $entityPrefix): self |
170
|
|
|
{ |
171
|
|
|
$this->entityPrefix = $entityPrefix; |
172
|
|
|
|
173
|
|
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function getEntityPrefix(): string|null |
177
|
|
|
{ |
178
|
|
|
return $this->entityPrefix; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public function setSortFields(bool|null $sortFields): self |
182
|
|
|
{ |
183
|
|
|
$this->sortFields = $sortFields; |
184
|
|
|
|
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function getSortFields(): bool|null |
189
|
|
|
{ |
190
|
|
|
return $this->sortFields; |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|