|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Gacela\Framework\Bootstrap; |
|
6
|
|
|
|
|
7
|
|
|
use Closure; |
|
8
|
|
|
use Gacela\Framework\ClassResolver\Cache\GacelaFileCache; |
|
9
|
|
|
use Gacela\Framework\Config\GacelaConfigBuilder\BindingsBuilder; |
|
10
|
|
|
use Gacela\Framework\Config\GacelaConfigBuilder\ConfigBuilder; |
|
11
|
|
|
use Gacela\Framework\Config\GacelaConfigBuilder\SuffixTypesBuilder; |
|
12
|
|
|
use Gacela\Framework\Container\Container; |
|
13
|
|
|
use Gacela\Framework\Event\Dispatcher\EventDispatcherInterface; |
|
14
|
|
|
use RuntimeException; |
|
15
|
|
|
|
|
16
|
|
|
use function is_callable; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @psalm-suppress ArgumentTypeCoercion,MixedArgumentTypeCoercion |
|
20
|
|
|
*/ |
|
21
|
|
|
final class SetupGacela extends AbstractSetupGacela |
|
22
|
|
|
{ |
|
23
|
|
|
public const shouldResetInMemoryCache = 'shouldResetInMemoryCache'; |
|
24
|
|
|
public const fileCacheEnabled = 'fileCacheEnabled'; |
|
25
|
|
|
public const fileCacheDirectory = 'fileCacheDirectory'; |
|
26
|
|
|
public const externalServices = 'externalServices'; |
|
27
|
|
|
public const projectNamespaces = 'projectNamespaces'; |
|
28
|
|
|
public const configKeyValues = 'configKeyValues'; |
|
29
|
|
|
public const servicesToExtend = 'servicesToExtend'; |
|
30
|
|
|
public const plugins = 'plugins'; |
|
31
|
|
|
public const extendConfig = 'extendConfig'; |
|
32
|
|
|
|
|
33
|
|
|
private const DEFAULT_ARE_EVENT_LISTENERS_ENABLED = true; |
|
34
|
|
|
private const DEFAULT_SHOULD_RESET_IN_MEMORY_CACHE = false; |
|
35
|
|
|
private const DEFAULT_FILE_CACHE_ENABLED = GacelaFileCache::DEFAULT_ENABLED_VALUE; |
|
36
|
|
|
private const DEFAULT_FILE_CACHE_DIRECTORY = GacelaFileCache::DEFAULT_DIRECTORY_VALUE; |
|
37
|
|
|
private const DEFAULT_PROJECT_NAMESPACES = []; |
|
38
|
|
|
private const DEFAULT_CONFIG_KEY_VALUES = []; |
|
39
|
|
|
private const DEFAULT_GENERIC_LISTENERS = []; |
|
40
|
|
|
private const DEFAULT_SPECIFIC_LISTENERS = []; |
|
41
|
|
|
private const DEFAULT_SERVICES_TO_EXTEND = []; |
|
42
|
|
|
private const DEFAULT_EXTEND_CONFIG = []; |
|
43
|
|
|
private const DEFAULT_PLUGINS = []; |
|
44
|
|
|
|
|
45
|
|
|
/** @var callable(ConfigBuilder):void */ |
|
46
|
|
|
private $configFn; |
|
47
|
|
|
|
|
48
|
|
|
/** @var callable(BindingsBuilder,array<string,mixed>):void */ |
|
49
|
|
|
private $bindingsFn; |
|
50
|
|
|
|
|
51
|
|
|
/** @var callable(SuffixTypesBuilder):void */ |
|
52
|
|
|
private $suffixTypesFn; |
|
53
|
|
|
|
|
54
|
|
|
/** @var ?array<string,class-string|object|callable> */ |
|
55
|
|
|
private ?array $externalServices = null; |
|
56
|
|
|
|
|
57
|
|
|
private ?ConfigBuilder $configBuilder = null; |
|
58
|
|
|
|
|
59
|
|
|
private ?SuffixTypesBuilder $suffixTypesBuilder = null; |
|
60
|
|
|
|
|
61
|
|
|
private ?BindingsBuilder $bindingsBuilder = null; |
|
62
|
|
|
|
|
63
|
|
|
private ?bool $shouldResetInMemoryCache = null; |
|
64
|
|
|
|
|
65
|
|
|
private ?bool $fileCacheEnabled = null; |
|
66
|
|
|
|
|
67
|
|
|
private ?string $fileCacheDirectory = null; |
|
68
|
|
|
|
|
69
|
|
|
/** @var ?list<string> */ |
|
70
|
|
|
private ?array $projectNamespaces = null; |
|
71
|
|
|
|
|
72
|
|
|
/** @var ?array<string,mixed> */ |
|
73
|
|
|
private ?array $configKeyValues = null; |
|
74
|
|
|
|
|
75
|
|
|
private ?bool $areEventListenersEnabled = null; |
|
76
|
|
|
|
|
77
|
|
|
/** @var ?list<callable> */ |
|
78
|
|
|
private ?array $genericListeners = null; |
|
79
|
|
|
|
|
80
|
|
|
/** @var ?array<class-string,list<callable>> */ |
|
81
|
|
|
private ?array $specificListeners = null; |
|
82
|
|
|
|
|
83
|
|
|
private ?EventDispatcherInterface $eventDispatcher = null; |
|
84
|
|
|
|
|
85
|
|
|
/** @var ?array<string,bool> */ |
|
86
|
|
|
private ?array $changedProperties = null; |
|
87
|
|
|
|
|
88
|
|
|
/** @var ?array<string,list<Closure>> */ |
|
89
|
|
|
private ?array $servicesToExtend = null; |
|
90
|
|
|
|
|
91
|
|
|
/** @var ?list<class-string> */ |
|
92
|
|
|
private ?array $extendConfig = null; |
|
93
|
|
|
|
|
94
|
|
|
/** @var ?list<class-string|callable> */ |
|
95
|
|
|
private ?array $plugins = null; |
|
96
|
|
|
|
|
97
|
114 |
|
public function __construct() |
|
98
|
|
|
{ |
|
99
|
114 |
|
$emptyFn = static function (): void { |
|
100
|
62 |
|
}; |
|
101
|
|
|
|
|
102
|
114 |
|
$this->configFn = $emptyFn; |
|
103
|
114 |
|
$this->bindingsFn = $emptyFn; |
|
104
|
114 |
|
$this->suffixTypesFn = $emptyFn; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public static function fromFile(string $gacelaFilePath): self |
|
108
|
|
|
{ |
|
109
|
|
|
if (!is_file($gacelaFilePath)) { |
|
110
|
|
|
throw new RuntimeException("Invalid file path: '{$gacelaFilePath}'"); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** @var callable(GacelaConfig):void|null $setupGacelaFileFn */ |
|
114
|
|
|
$setupGacelaFileFn = include $gacelaFilePath; |
|
115
|
|
|
if (!is_callable($setupGacelaFileFn)) { |
|
116
|
|
|
return new self(); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return self::fromCallable($setupGacelaFileFn); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param callable(GacelaConfig):void $setupGacelaFileFn |
|
124
|
|
|
*/ |
|
125
|
62 |
|
public static function fromCallable(callable $setupGacelaFileFn): self |
|
126
|
|
|
{ |
|
127
|
62 |
|
$gacelaConfig = new GacelaConfig(); |
|
128
|
62 |
|
$setupGacelaFileFn($gacelaConfig); |
|
129
|
62 |
|
self::runExtendConfig($gacelaConfig); |
|
130
|
|
|
|
|
131
|
62 |
|
return self::fromGacelaConfig($gacelaConfig); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
80 |
|
public static function fromGacelaConfig(GacelaConfig $gacelaConfig): self |
|
135
|
|
|
{ |
|
136
|
80 |
|
$build = $gacelaConfig->build(); |
|
137
|
|
|
|
|
138
|
80 |
|
return (new self()) |
|
139
|
80 |
|
->setExternalServices($build['external-services']) |
|
140
|
80 |
|
->setConfigBuilder($build['config-builder']) |
|
141
|
80 |
|
->setSuffixTypesBuilder($build['suffix-types-builder']) |
|
142
|
80 |
|
->setBindingsBuilder($build['bindings-builder']) |
|
143
|
80 |
|
->setShouldResetInMemoryCache($build['should-reset-in-memory-cache']) |
|
144
|
80 |
|
->setFileCacheEnabled($build['file-cache-enabled']) |
|
145
|
80 |
|
->setFileCacheDirectory($build['file-cache-directory']) |
|
146
|
80 |
|
->setProjectNamespaces($build['project-namespaces']) |
|
147
|
80 |
|
->setConfigKeyValues($build['config-key-values']) |
|
148
|
80 |
|
->setAreEventListenersEnabled($build['are-event-listeners-enabled']) |
|
149
|
80 |
|
->setGenericListeners($build['generic-listeners']) |
|
150
|
80 |
|
->setSpecificListeners($build['specific-listeners']) |
|
151
|
80 |
|
->setExtendConfig($build['extend-config']) |
|
152
|
80 |
|
->setPlugins($build['plugins']) |
|
153
|
80 |
|
->setServicesToExtend($build['instances-to-extend']); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @param array<string,class-string|object|callable> $array |
|
158
|
|
|
*/ |
|
159
|
83 |
|
public function setExternalServices(array $array): self |
|
160
|
|
|
{ |
|
161
|
83 |
|
$this->markPropertyChanged(self::externalServices, true); |
|
162
|
83 |
|
$this->externalServices = $array; |
|
163
|
|
|
|
|
164
|
83 |
|
return $this; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
80 |
|
public function setConfigBuilder(ConfigBuilder $builder): self |
|
168
|
|
|
{ |
|
169
|
80 |
|
$this->configBuilder = $builder; |
|
170
|
|
|
|
|
171
|
80 |
|
return $this; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
80 |
|
public function setSuffixTypesBuilder(SuffixTypesBuilder $builder): self |
|
175
|
|
|
{ |
|
176
|
80 |
|
$this->suffixTypesBuilder = $builder; |
|
177
|
|
|
|
|
178
|
80 |
|
return $this; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
80 |
|
public function setBindingsBuilder(BindingsBuilder $builder): self |
|
182
|
|
|
{ |
|
183
|
80 |
|
$this->bindingsBuilder = $builder; |
|
184
|
|
|
|
|
185
|
80 |
|
return $this; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* @param callable(ConfigBuilder):void $callable |
|
190
|
|
|
*/ |
|
191
|
3 |
|
public function setConfigFn(callable $callable): self |
|
192
|
|
|
{ |
|
193
|
3 |
|
$this->configFn = $callable; |
|
194
|
|
|
|
|
195
|
3 |
|
return $this; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
63 |
|
public function buildConfig(ConfigBuilder $builder): ConfigBuilder |
|
199
|
|
|
{ |
|
200
|
63 |
|
$builder = parent::buildConfig($builder); |
|
201
|
|
|
|
|
202
|
63 |
|
if ($this->configBuilder) { |
|
203
|
55 |
|
$builder = $this->configBuilder; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
63 |
|
($this->configFn)($builder); |
|
207
|
|
|
|
|
208
|
63 |
|
return $builder; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @param callable(BindingsBuilder,array<string,mixed>):void $callable |
|
213
|
|
|
*/ |
|
214
|
3 |
|
public function setBindingsFn(callable $callable): self |
|
215
|
|
|
{ |
|
216
|
3 |
|
$this->bindingsFn = $callable; |
|
217
|
|
|
|
|
218
|
3 |
|
return $this; |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* Define the mapping between interfaces and concretions, so Gacela services will auto-resolve them automatically. |
|
223
|
|
|
* |
|
224
|
|
|
* @param array<string,class-string|object|callable> $externalServices |
|
225
|
|
|
*/ |
|
226
|
63 |
|
public function buildBindings( |
|
227
|
|
|
BindingsBuilder $builder, |
|
228
|
|
|
array $externalServices, |
|
229
|
|
|
): BindingsBuilder { |
|
230
|
63 |
|
$builder = parent::buildBindings($builder, $externalServices); |
|
231
|
|
|
|
|
232
|
63 |
|
if ($this->bindingsBuilder) { |
|
233
|
55 |
|
$builder = $this->bindingsBuilder; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
63 |
|
($this->bindingsFn)( |
|
237
|
63 |
|
$builder, |
|
238
|
63 |
|
array_merge($this->externalServices ?? [], $externalServices) |
|
239
|
63 |
|
); |
|
240
|
|
|
|
|
241
|
63 |
|
return $builder; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* @param callable(SuffixTypesBuilder):void $callable |
|
246
|
|
|
*/ |
|
247
|
3 |
|
public function setSuffixTypesFn(callable $callable): self |
|
248
|
|
|
{ |
|
249
|
3 |
|
$this->suffixTypesFn = $callable; |
|
250
|
|
|
|
|
251
|
3 |
|
return $this; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* Allow overriding gacela resolvable types. |
|
256
|
|
|
*/ |
|
257
|
63 |
|
public function buildSuffixTypes(SuffixTypesBuilder $builder): SuffixTypesBuilder |
|
258
|
|
|
{ |
|
259
|
63 |
|
$builder = parent::buildSuffixTypes($builder); |
|
260
|
|
|
|
|
261
|
63 |
|
if ($this->suffixTypesBuilder) { |
|
262
|
55 |
|
$builder = $this->suffixTypesBuilder; |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
63 |
|
($this->suffixTypesFn)($builder); |
|
266
|
|
|
|
|
267
|
63 |
|
return $builder; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* @return array<string, class-string|object|callable> |
|
272
|
|
|
*/ |
|
273
|
27 |
|
public function externalServices(): array |
|
274
|
|
|
{ |
|
275
|
27 |
|
return array_merge( |
|
276
|
27 |
|
parent::externalServices(), |
|
277
|
27 |
|
$this->externalServices ?? [], |
|
278
|
27 |
|
); |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
80 |
|
public function setShouldResetInMemoryCache(?bool $flag): self |
|
282
|
|
|
{ |
|
283
|
80 |
|
$this->markPropertyChanged(self::shouldResetInMemoryCache, $flag); |
|
284
|
80 |
|
$this->shouldResetInMemoryCache = $flag ?? self::DEFAULT_SHOULD_RESET_IN_MEMORY_CACHE; |
|
285
|
|
|
|
|
286
|
80 |
|
return $this; |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
89 |
|
public function shouldResetInMemoryCache(): bool |
|
290
|
|
|
{ |
|
291
|
89 |
|
return (bool)$this->shouldResetInMemoryCache; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
39 |
|
public function isFileCacheEnabled(): bool |
|
295
|
|
|
{ |
|
296
|
39 |
|
return (bool)$this->fileCacheEnabled; |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
7 |
|
public function getFileCacheDirectory(): string |
|
300
|
|
|
{ |
|
301
|
7 |
|
return (string)$this->fileCacheDirectory; |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
80 |
|
public function setFileCacheDirectory(?string $dir): self |
|
305
|
|
|
{ |
|
306
|
80 |
|
$this->markPropertyChanged(self::fileCacheDirectory, $dir); |
|
307
|
80 |
|
$this->fileCacheDirectory = $dir ?? self::DEFAULT_FILE_CACHE_DIRECTORY; |
|
308
|
|
|
|
|
309
|
80 |
|
return $this; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
/** |
|
313
|
|
|
* @param ?list<string> $list |
|
314
|
|
|
*/ |
|
315
|
80 |
|
public function setProjectNamespaces(?array $list): self |
|
316
|
|
|
{ |
|
317
|
80 |
|
$this->markPropertyChanged(self::projectNamespaces, $list); |
|
318
|
80 |
|
$this->projectNamespaces = $list ?? self::DEFAULT_PROJECT_NAMESPACES; |
|
319
|
|
|
|
|
320
|
80 |
|
return $this; |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
/** |
|
324
|
|
|
* @return list<string> |
|
325
|
|
|
*/ |
|
326
|
39 |
|
public function getProjectNamespaces(): array |
|
327
|
|
|
{ |
|
328
|
39 |
|
return (array)$this->projectNamespaces; |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
/** |
|
332
|
|
|
* @return array<string,mixed> |
|
333
|
|
|
*/ |
|
334
|
89 |
|
public function getConfigKeyValues(): array |
|
335
|
|
|
{ |
|
336
|
89 |
|
return (array)$this->configKeyValues; |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
48 |
|
public function getEventDispatcher(): EventDispatcherInterface |
|
340
|
|
|
{ |
|
341
|
48 |
|
return $this->eventDispatcher ??= SetupEventDispatcher::getDispatcher($this); |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
/** |
|
345
|
|
|
* @return array<string,list<Closure>> |
|
346
|
|
|
*/ |
|
347
|
101 |
|
public function getServicesToExtend(): array |
|
348
|
|
|
{ |
|
349
|
101 |
|
return (array)$this->servicesToExtend; |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
80 |
|
public function setFileCacheEnabled(?bool $flag): self |
|
353
|
|
|
{ |
|
354
|
80 |
|
$this->markPropertyChanged(self::fileCacheEnabled, $flag); |
|
355
|
80 |
|
$this->fileCacheEnabled = $flag ?? self::DEFAULT_FILE_CACHE_ENABLED; |
|
356
|
|
|
|
|
357
|
80 |
|
return $this; |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
58 |
|
public function canCreateEventDispatcher(): bool |
|
361
|
|
|
{ |
|
362
|
58 |
|
return $this->areEventListenersEnabled |
|
363
|
58 |
|
&& $this->hasEventListeners(); |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
/** |
|
367
|
|
|
* @param ?array<string,mixed> $configKeyValues |
|
368
|
|
|
*/ |
|
369
|
80 |
|
public function setConfigKeyValues(?array $configKeyValues): self |
|
370
|
|
|
{ |
|
371
|
80 |
|
$this->markPropertyChanged(self::configKeyValues, $configKeyValues); |
|
372
|
80 |
|
$this->configKeyValues = $configKeyValues ?? self::DEFAULT_CONFIG_KEY_VALUES; |
|
373
|
|
|
|
|
374
|
80 |
|
return $this; |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
/** |
|
378
|
|
|
* @return array<class-string,list<callable>>|null |
|
379
|
|
|
*/ |
|
380
|
13 |
|
public function getSpecificListeners(): ?array |
|
381
|
|
|
{ |
|
382
|
13 |
|
return $this->specificListeners; |
|
383
|
|
|
} |
|
384
|
|
|
|
|
385
|
|
|
/** |
|
386
|
|
|
* @return list<callable>|null |
|
387
|
|
|
*/ |
|
388
|
13 |
|
public function getGenericListeners(): ?array |
|
389
|
|
|
{ |
|
390
|
13 |
|
return $this->genericListeners; |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
27 |
|
public function isPropertyChanged(string $name): bool |
|
394
|
|
|
{ |
|
395
|
27 |
|
return $this->changedProperties[$name] ?? false; |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
27 |
|
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): self |
|
399
|
|
|
{ |
|
400
|
27 |
|
$this->eventDispatcher = $eventDispatcher; |
|
401
|
|
|
|
|
402
|
27 |
|
return $this; |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
27 |
|
public function combine(self $other): self |
|
406
|
|
|
{ |
|
407
|
27 |
|
return (new SetupCombinator($this))->combine($other); |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
/** |
|
411
|
|
|
* @param list<Closure> $servicesToExtend |
|
412
|
|
|
*/ |
|
413
|
1 |
|
public function addServicesToExtend(string $serviceId, array $servicesToExtend): self |
|
414
|
|
|
{ |
|
415
|
1 |
|
$this->servicesToExtend[$serviceId] ??= []; |
|
416
|
1 |
|
$this->servicesToExtend[$serviceId] = array_merge( |
|
417
|
1 |
|
$this->servicesToExtend[$serviceId], |
|
418
|
1 |
|
$servicesToExtend, |
|
419
|
1 |
|
); |
|
420
|
|
|
|
|
421
|
1 |
|
return $this; |
|
422
|
|
|
} |
|
423
|
|
|
|
|
424
|
27 |
|
public function combineExternalServices(array $list): void |
|
425
|
|
|
{ |
|
426
|
27 |
|
$this->setExternalServices(array_merge($this->externalServices ?? [], $list)); |
|
427
|
|
|
} |
|
428
|
|
|
|
|
429
|
1 |
|
public function combineProjectNamespaces(array $list): void |
|
430
|
|
|
{ |
|
431
|
1 |
|
$this->setProjectNamespaces(array_merge($this->projectNamespaces ?? [], $list)); |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
1 |
|
public function combineConfigKeyValues(array $list): void |
|
435
|
|
|
{ |
|
436
|
1 |
|
$this->setConfigKeyValues(array_merge($this->configKeyValues ?? [], $list)); |
|
437
|
|
|
} |
|
438
|
|
|
|
|
439
|
|
|
/** |
|
440
|
|
|
* @param list<class-string> $list |
|
441
|
|
|
*/ |
|
442
|
|
|
public function combineExtendConfig(array $list): void |
|
443
|
|
|
{ |
|
444
|
|
|
$this->setExtendConfig(array_merge($this->extendConfig ?? [], $list)); |
|
445
|
|
|
} |
|
446
|
|
|
|
|
447
|
|
|
/** |
|
448
|
|
|
* @param list<class-string|callable> $list |
|
449
|
|
|
*/ |
|
450
|
1 |
|
public function combinePlugins(array $list): void |
|
451
|
|
|
{ |
|
452
|
1 |
|
$this->setPlugins(array_merge($this->plugins ?? [], $list)); |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
/** |
|
456
|
|
|
* @return list<class-string> |
|
457
|
|
|
*/ |
|
458
|
|
|
public function getExtendConfig(): array |
|
459
|
|
|
{ |
|
460
|
|
|
return (array)$this->extendConfig; |
|
461
|
|
|
} |
|
462
|
|
|
|
|
463
|
|
|
/** |
|
464
|
|
|
* @return list<class-string|callable> |
|
465
|
|
|
*/ |
|
466
|
89 |
|
public function getPlugins(): array |
|
467
|
|
|
{ |
|
468
|
89 |
|
return (array)$this->plugins; |
|
469
|
|
|
} |
|
470
|
|
|
|
|
471
|
62 |
|
private static function runExtendConfig(GacelaConfig $gacelaConfig): void |
|
472
|
|
|
{ |
|
473
|
62 |
|
$extendConfigs = $gacelaConfig->build()['extend-config'] ?? []; |
|
474
|
|
|
|
|
475
|
62 |
|
if ($extendConfigs === []) { |
|
476
|
61 |
|
return; |
|
477
|
|
|
} |
|
478
|
|
|
|
|
479
|
1 |
|
$container = new Container(); |
|
480
|
|
|
|
|
481
|
1 |
|
foreach ($extendConfigs as $extendConfig) { |
|
482
|
|
|
/** @var callable $configToExtend */ |
|
483
|
1 |
|
$configToExtend = $container->get($extendConfig); |
|
484
|
1 |
|
$configToExtend($gacelaConfig); |
|
485
|
|
|
} |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
80 |
|
private function setAreEventListenersEnabled(?bool $flag): self |
|
489
|
|
|
{ |
|
490
|
80 |
|
$this->areEventListenersEnabled = $flag ?? self::DEFAULT_ARE_EVENT_LISTENERS_ENABLED; |
|
491
|
|
|
|
|
492
|
80 |
|
return $this; |
|
493
|
|
|
} |
|
494
|
|
|
|
|
495
|
58 |
|
private function hasEventListeners(): bool |
|
496
|
|
|
{ |
|
497
|
58 |
|
return !empty($this->genericListeners) |
|
498
|
58 |
|
|| !empty($this->specificListeners); |
|
499
|
|
|
} |
|
500
|
|
|
|
|
501
|
|
|
/** |
|
502
|
|
|
* @param ?list<callable> $listeners |
|
503
|
|
|
*/ |
|
504
|
80 |
|
private function setGenericListeners(?array $listeners): self |
|
505
|
|
|
{ |
|
506
|
80 |
|
$this->genericListeners = $listeners ?? self::DEFAULT_GENERIC_LISTENERS; |
|
507
|
|
|
|
|
508
|
80 |
|
return $this; |
|
509
|
|
|
} |
|
510
|
|
|
|
|
511
|
|
|
/** |
|
512
|
|
|
* @param ?array<string,list<Closure>> $list |
|
513
|
|
|
*/ |
|
514
|
80 |
|
private function setServicesToExtend(?array $list): self |
|
515
|
|
|
{ |
|
516
|
80 |
|
$this->markPropertyChanged(self::servicesToExtend, $list); |
|
517
|
80 |
|
$this->servicesToExtend = $list ?? self::DEFAULT_SERVICES_TO_EXTEND; |
|
518
|
|
|
|
|
519
|
80 |
|
return $this; |
|
520
|
|
|
} |
|
521
|
|
|
|
|
522
|
|
|
/** |
|
523
|
|
|
* @param ?list<class-string> $list |
|
524
|
|
|
*/ |
|
525
|
80 |
|
private function setExtendConfig(?array $list): self |
|
526
|
|
|
{ |
|
527
|
80 |
|
$this->markPropertyChanged(self::extendConfig, $list); |
|
528
|
80 |
|
$this->extendConfig = $list ?? self::DEFAULT_EXTEND_CONFIG; |
|
529
|
|
|
|
|
530
|
80 |
|
return $this; |
|
531
|
|
|
} |
|
532
|
|
|
|
|
533
|
|
|
/** |
|
534
|
|
|
* @param ?list<class-string|callable> $list |
|
535
|
|
|
*/ |
|
536
|
80 |
|
private function setPlugins(?array $list): self |
|
537
|
|
|
{ |
|
538
|
80 |
|
$this->markPropertyChanged(self::plugins, $list); |
|
539
|
80 |
|
$this->plugins = $list ?? self::DEFAULT_PLUGINS; |
|
540
|
|
|
|
|
541
|
80 |
|
return $this; |
|
542
|
|
|
} |
|
543
|
|
|
|
|
544
|
|
|
/** |
|
545
|
|
|
* @param ?array<class-string,list<callable>> $listeners |
|
546
|
|
|
*/ |
|
547
|
80 |
|
private function setSpecificListeners(?array $listeners): self |
|
548
|
|
|
{ |
|
549
|
80 |
|
$this->specificListeners = $listeners ?? self::DEFAULT_SPECIFIC_LISTENERS; |
|
550
|
|
|
|
|
551
|
80 |
|
return $this; |
|
552
|
|
|
} |
|
553
|
|
|
|
|
554
|
83 |
|
private function markPropertyChanged(string $name, mixed $value): void |
|
555
|
|
|
{ |
|
556
|
83 |
|
$this->changedProperties[$name] = ($value !== null); |
|
557
|
|
|
} |
|
558
|
|
|
} |
|
559
|
|
|
|