Passed
Pull Request — main (#112)
by Tom
03:05
created

Config::setSharedTypeManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApiSkeletons\Doctrine\GraphQL;
6
7
/**
8
 * This class is used for parameter differentiation when creating the driver
9
 *   $partialContext->setLimit(1000);
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 When set to false the driver will have a unique instance of the
66
     *           TypeManager.  The default is true so all drivers share the same
67
     *           TypeManager.  This prevents collisions when using more than one
68
     *           TypeManager.  But if you're using events then a shared
69
     *           TypeManager may cause unexpected results.
70
     */
71
    protected bool $sharedTypeManager = true;
72
73
    /** @param mixed[] $config */
74
    public function __construct(array $config = [])
75
    {
76
        /**
77
         * Dynamic setters will fail for invalid settings and allow for
78
         * validation of field types through setters
79
         */
80
        foreach ($config as $setting => $value) {
81
            $setter = 'set' . $setting;
82
            $this->$setter($value);
83
        }
84
    }
85
86
    protected function setGroup(string $group): self
87
    {
88
        $this->group = $group;
89
90
        return $this;
91
    }
92
93
    public function getGroup(): string
94
    {
95
        return $this->group;
96
    }
97
98
    protected function setGroupSuffix(string|null $groupSuffix): self
99
    {
100
        $this->groupSuffix = $groupSuffix;
101
102
        return $this;
103
    }
104
105
    public function getGroupSuffix(): string|null
106
    {
107
        return $this->groupSuffix;
108
    }
109
110
    protected function setUseHydratorCache(bool $useHydratorCache): self
111
    {
112
        $this->useHydratorCache = $useHydratorCache;
113
114
        return $this;
115
    }
116
117
    public function getUseHydratorCache(): bool
118
    {
119
        return $this->useHydratorCache;
120
    }
121
122
    protected function setLimit(int $limit): self
123
    {
124
        $this->limit = $limit;
125
126
        return $this;
127
    }
128
129
    public function getLimit(): int
130
    {
131
        return $this->limit;
132
    }
133
134
    protected function setGlobalEnable(bool $globalEnable): self
135
    {
136
        $this->globalEnable = $globalEnable;
137
138
        return $this;
139
    }
140
141
    public function getGlobalEnable(): bool
142
    {
143
        return $this->globalEnable;
144
    }
145
146
    /** @param string[] $globalIgnore */
147
    protected function setGlobalIgnore(array $globalIgnore): self
148
    {
149
        $this->globalIgnore = $globalIgnore;
150
151
        return $this;
152
    }
153
154
    /** @return string[] */
155
    public function getGlobalIgnore(): array
156
    {
157
        return $this->globalIgnore;
158
    }
159
160
    protected function setGlobalByValue(bool|null $globalByValue): self
161
    {
162
        $this->globalByValue = $globalByValue;
163
164
        return $this;
165
    }
166
167
    public function getGlobalByValue(): bool|null
168
    {
169
        return $this->globalByValue;
170
    }
171
172
    protected function setEntityPrefix(string|null $entityPrefix): self
173
    {
174
        $this->entityPrefix = $entityPrefix;
175
176
        return $this;
177
    }
178
179
    public function getEntityPrefix(): string|null
180
    {
181
        return $this->entityPrefix;
182
    }
183
184
    protected function setSharedTypeManager(bool $sharedTypeManger): self
185
    {
186
        $this->sharedTypeManager = $sharedTypeManger;
187
188
        return $this;
189
    }
190
191
    public function getSharedTypeManager(): bool
192
    {
193
        return $this->sharedTypeManager;
194
    }
195
}
196