1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Gacela\Framework\Bootstrap\Setup; |
6
|
|
|
|
7
|
|
|
use Gacela\Framework\Bootstrap\SetupGacela; |
8
|
|
|
use ReflectionMethod; |
9
|
|
|
|
10
|
|
|
use function array_merge; |
11
|
|
|
use function array_unique; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Handles combining/merging of properties for SetupGacela. |
15
|
|
|
*/ |
16
|
|
|
final class Combiner |
17
|
|
|
{ |
18
|
|
|
public function __construct( |
19
|
|
|
private readonly SetupGacela $setup, |
20
|
|
|
) { |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param array<string,class-string|object|callable> $list |
25
|
|
|
*/ |
26
|
|
|
public function combineExternalServices(array $list): void |
27
|
|
|
{ |
28
|
|
|
$current = $this->setup->externalServices(); |
29
|
|
|
$this->setup->setExternalServices(array_merge($current, $list)); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param list<string> $list |
34
|
|
|
*/ |
35
|
|
|
public function combineProjectNamespaces(array $list): void |
36
|
|
|
{ |
37
|
|
|
$current = $this->setup->getProjectNamespaces(); |
38
|
|
|
$this->setup->setProjectNamespaces(array_merge($current, $list)); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param array<string,mixed> $list |
43
|
|
|
*/ |
44
|
|
|
public function combineConfigKeyValues(array $list): void |
45
|
|
|
{ |
46
|
|
|
$current = $this->setup->getConfigKeyValues(); |
47
|
|
|
$this->setup->setConfigKeyValues(array_merge($current, $list)); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param list<class-string> $list |
52
|
|
|
*/ |
53
|
|
|
public function combineGacelaConfigsToExtend(array $list): void |
54
|
|
|
{ |
55
|
|
|
$current = $this->setup->getGacelaConfigsToExtend(); |
56
|
|
|
|
57
|
|
|
// Use reflection to call private method setGacelaConfigsToExtend |
58
|
|
|
$method = new ReflectionMethod($this->setup, 'setGacelaConfigsToExtend'); |
59
|
|
|
$method->setAccessible(true); |
60
|
|
|
$method->invoke($this->setup, array_unique(array_merge($current, $list))); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param list<class-string|callable> $list |
65
|
|
|
*/ |
66
|
|
|
public function combinePlugins(array $list): void |
67
|
|
|
{ |
68
|
|
|
$current = $this->setup->getPlugins(); |
69
|
|
|
|
70
|
|
|
// Use reflection to call private method setPlugins |
71
|
|
|
$method = new ReflectionMethod($this->setup, 'setPlugins'); |
72
|
|
|
$method->setAccessible(true); |
73
|
|
|
$method->invoke($this->setup, array_merge($current, $list)); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|