|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Gacela\Framework\Bootstrap\Setup; |
|
6
|
|
|
|
|
7
|
|
|
use Closure; |
|
8
|
|
|
use Gacela\Framework\Bootstrap\SetupGacela; |
|
9
|
|
|
|
|
10
|
|
|
use function array_merge; |
|
11
|
|
|
use function array_unique; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Merges individual properties into a SetupGacela instance. |
|
15
|
|
|
*/ |
|
16
|
|
|
final class PropertyMerger |
|
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 mergeExternalServices(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 mergeProjectNamespaces(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 mergeConfigKeyValues(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 mergeGacelaConfigsToExtend(array $list): void |
|
54
|
|
|
{ |
|
55
|
|
|
$current = $this->setup->getGacelaConfigsToExtend(); |
|
56
|
|
|
/** @var list<class-string> $merged */ |
|
57
|
|
|
$merged = array_values(array_unique(array_merge($current, $list))); |
|
58
|
|
|
$this->setup->setGacelaConfigsToExtend($merged); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param list<class-string|callable> $list |
|
63
|
|
|
*/ |
|
64
|
|
|
public function mergePlugins(array $list): void |
|
65
|
|
|
{ |
|
66
|
|
|
$current = $this->setup->getPlugins(); |
|
67
|
|
|
$this->setup->setPlugins(array_merge($current, $list)); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param array<string,Closure> $list |
|
72
|
|
|
*/ |
|
73
|
|
|
public function mergeFactories(array $list): void |
|
74
|
|
|
{ |
|
75
|
|
|
$current = $this->setup->getFactories(); |
|
76
|
|
|
$this->setup->setFactories(array_merge($current, $list)); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param array<string,Closure> $list |
|
81
|
|
|
*/ |
|
82
|
|
|
public function mergeProtectedServices(array $list): void |
|
83
|
|
|
{ |
|
84
|
|
|
$current = $this->setup->getProtectedServices(); |
|
85
|
|
|
$this->setup->setProtectedServices(array_merge($current, $list)); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param array<string,string> $list |
|
90
|
|
|
*/ |
|
91
|
|
|
public function mergeAliases(array $list): void |
|
92
|
|
|
{ |
|
93
|
|
|
$current = $this->setup->getAliases(); |
|
94
|
|
|
$this->setup->setAliases(array_merge($current, $list)); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param array<string,array<class-string,class-string|callable|object>> $list |
|
|
|
|
|
|
99
|
|
|
*/ |
|
100
|
|
|
public function mergeContextualBindings(array $list): void |
|
101
|
|
|
{ |
|
102
|
|
|
$current = $this->setup->getContextualBindings(); |
|
103
|
|
|
$merged = $current; |
|
104
|
|
|
|
|
105
|
|
|
foreach ($list as $concrete => $bindings) { |
|
106
|
|
|
if (!isset($merged[$concrete])) { |
|
107
|
|
|
$merged[$concrete] = []; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
$merged[$concrete] = array_merge($merged[$concrete], $bindings); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
$this->setup->setContextualBindings($merged); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|