|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Arp\LaminasDoctrine\Config; |
|
6
|
|
|
|
|
7
|
|
|
class DoctrineConfig implements DoctrineConfigInterface |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var array<string, mixed> |
|
11
|
|
|
*/ |
|
12
|
|
|
private array $config = []; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @param array<string, mixed> $config |
|
16
|
|
|
*/ |
|
17
|
|
|
public function __construct( |
|
18
|
|
|
private readonly EntityManagerConfigs $entityManagerConfigs, |
|
19
|
|
|
private readonly ConnectionConfigs $connectionConfigs, |
|
20
|
|
|
private readonly ConfigurationConfigs $configurationConfigs, |
|
21
|
|
|
array $config |
|
22
|
|
|
) { |
|
23
|
|
|
$this->configure($config); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function hasConnectionConfig(string $name): bool |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->connectionConfigs->hasConnectionConfig($name); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return array<string, mixed> |
|
33
|
|
|
*/ |
|
34
|
|
|
public function getConnectionConfig(string $name): array |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->connectionConfigs->getConnectionConfig($name); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param array<string, array<mixed>> $connectionConfigs |
|
41
|
|
|
*/ |
|
42
|
|
|
public function setConnectionConfigs(array $connectionConfigs): void |
|
43
|
|
|
{ |
|
44
|
|
|
foreach ($connectionConfigs as $name => $connectionConfig) { |
|
45
|
|
|
$this->setConnectionConfig($name, $connectionConfig); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param array<string, mixed> $connectionConfig |
|
51
|
|
|
*/ |
|
52
|
|
|
public function setConnectionConfig(string $name, array $connectionConfig): void |
|
53
|
|
|
{ |
|
54
|
|
|
$this->connectionConfigs->setConnectionConfig($name, $connectionConfig); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function hasEntityManagerConfig(string $name): bool |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->entityManagerConfigs->hasEntityManagerConfig($name); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return array<string, mixed> |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getEntityManagerConfig(string $name): array |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->entityManagerConfigs->getEntityManagerConfig($name); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param array<string, mixed> $config |
|
72
|
|
|
*/ |
|
73
|
|
|
public function setEntityManagerConfig(string $name, array $config): void |
|
74
|
|
|
{ |
|
75
|
|
|
$this->entityManagerConfigs->setEntityManagerConfig($name, $config); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function hasConfigurationConfig(string $name): bool |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->configurationConfigs->hasConfigurationConfig($name); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return array<string, mixed> |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getConfigurationConfig(string $name): array |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->configurationConfigs->getConfigurationConfig($name); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param array<string, mixed> $config |
|
93
|
|
|
*/ |
|
94
|
|
|
public function setConfigurationConfig(string $name, array $config): void |
|
95
|
|
|
{ |
|
96
|
|
|
$this->configurationConfigs->setConfigurationConfig($name, $config); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function hasDriverConfig(string $name): bool |
|
100
|
|
|
{ |
|
101
|
|
|
return isset($this->config['driver'][$name]); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return array<string, mixed> |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getDriverConfig(string $name): array |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->config['driver'][$name] ?? []; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param array<string, mixed> $config |
|
114
|
|
|
*/ |
|
115
|
|
|
public function setDriverConfig(string $name, array $config): void |
|
116
|
|
|
{ |
|
117
|
|
|
$this->config['driver'][$name] = $config; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return array<string, mixed> |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getEntityResolverConfig(string $name): array |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->config['entity_resolver'][$name] ?? []; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param array<string, mixed> $config |
|
130
|
|
|
*/ |
|
131
|
|
|
public function setEntityResolverConfig(string $name, array $config): void |
|
132
|
|
|
{ |
|
133
|
|
|
$this->config['entity_resolver'][$name] = $config; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function hasCacheConfig(string $name): bool |
|
137
|
|
|
{ |
|
138
|
|
|
return isset($this->config['cache'][$name]); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @return array<string, mixed> |
|
143
|
|
|
*/ |
|
144
|
|
|
public function getCacheConfig(string $name): array |
|
145
|
|
|
{ |
|
146
|
|
|
return $this->config['cache'][$name] ?? []; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @param array<string, mixed> $config |
|
151
|
|
|
*/ |
|
152
|
|
|
public function setCacheConfig(string $name, array $config): void |
|
153
|
|
|
{ |
|
154
|
|
|
$this->config['cache'][$name] = $config; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @param array<string, mixed> $config |
|
159
|
|
|
*/ |
|
160
|
|
|
public function configure(array $config): void |
|
161
|
|
|
{ |
|
162
|
|
|
if (!empty($config['connection'])) { |
|
163
|
|
|
foreach ($config['connection'] as $name => $configuration) { |
|
164
|
|
|
$this->setConnectionConfig($name, $configuration); |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
if (!empty($config['configuration'])) { |
|
169
|
|
|
foreach ($config['configuration'] as $name => $configuration) { |
|
170
|
|
|
$this->setConfigurationConfig($name, $configuration); |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
if (!empty($config['entitymanager'])) { |
|
175
|
|
|
foreach ($config['entitymanager'] as $name => $configuration) { |
|
176
|
|
|
$this->setEntityManagerConfig($name, $configuration); |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
if (!empty($config['driver'])) { |
|
181
|
|
|
foreach ($config['driver'] as $name => $configuration) { |
|
182
|
|
|
$this->setDriverConfig($name, $configuration); |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
if (!empty($config['cache'])) { |
|
187
|
|
|
foreach ($config['cache'] as $name => $configuration) { |
|
188
|
|
|
$this->setCacheConfig($name, $configuration); |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
if (!empty($config['entity_resolver'])) { |
|
193
|
|
|
foreach ($config['entity_resolver'] as $name => $configuration) { |
|
194
|
|
|
$this->setEntityResolverConfig($name, $configuration); |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|