|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bdf\PrimeBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Bdf\Prime\Configuration as PrimeConfiguration; |
|
6
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
7
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
|
8
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
9
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Configuration. |
|
13
|
|
|
*/ |
|
14
|
|
|
class Configuration implements ConfigurationInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var bool |
|
18
|
|
|
*/ |
|
19
|
|
|
private $debug; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param bool $debug Whether to use the debug mode |
|
23
|
|
|
*/ |
|
24
|
7 |
|
public function __construct($debug = false) |
|
25
|
|
|
{ |
|
26
|
7 |
|
$this->debug = (bool) $debug; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritDoc} |
|
31
|
|
|
*/ |
|
32
|
7 |
|
public function getConfigTreeBuilder() |
|
33
|
|
|
{ |
|
34
|
7 |
|
$treeBuilder = new TreeBuilder('prime'); |
|
35
|
7 |
|
$node = $treeBuilder->getRootNode(); |
|
36
|
7 |
|
$node |
|
37
|
7 |
|
->children() |
|
38
|
7 |
|
->booleanNode('activerecord')->defaultFalse()->end() |
|
39
|
7 |
|
->scalarNode('hydrators')->defaultValue('%kernel.cache_dir%/prime/hydrators/loader.php')->end() |
|
40
|
7 |
|
->scalarNode('serializer')->info('The bdf serializer service id.')->end() |
|
41
|
7 |
|
->scalarNode('default_connection')->defaultNull()->end() |
|
42
|
7 |
|
->append($this->getConnectionsNode()) |
|
43
|
7 |
|
->append($this->getMigrationNode()) |
|
44
|
7 |
|
->append($this->getCacheNode()) |
|
45
|
7 |
|
->end() |
|
46
|
7 |
|
; |
|
47
|
|
|
|
|
48
|
7 |
|
$this->configureConfigurationNode($node, true); |
|
49
|
|
|
|
|
50
|
7 |
|
return $treeBuilder; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Adds the configuration node of the connection |
|
55
|
|
|
* Could be the global config or a connection config. |
|
56
|
|
|
*/ |
|
57
|
7 |
|
private function configureConfigurationNode(ArrayNodeDefinition $node, bool $addDefault): void |
|
58
|
|
|
{ |
|
59
|
7 |
|
$parametersNode = $node->children(); |
|
60
|
|
|
|
|
61
|
7 |
|
$loggingNode = $parametersNode->booleanNode('logging'); |
|
62
|
7 |
|
$profilingNode = $parametersNode->booleanNode('profiling'); |
|
63
|
7 |
|
$autoCommitNode = $parametersNode->booleanNode('auto_commit'); |
|
64
|
|
|
|
|
65
|
7 |
|
if (true === $addDefault) { |
|
66
|
7 |
|
$loggingNode->defaultValue($this->debug); |
|
67
|
7 |
|
$profilingNode->defaultValue($this->debug); |
|
68
|
7 |
|
$autoCommitNode->defaultNull(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
7 |
|
$parametersNode->append($this->getTypesNode()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return NodeDefinition |
|
76
|
|
|
*/ |
|
77
|
7 |
|
private function getConnectionsNode() |
|
78
|
|
|
{ |
|
79
|
7 |
|
$root = (new TreeBuilder('connections'))->getRootNode(); |
|
80
|
|
|
|
|
81
|
7 |
|
$connectionNode = $root |
|
82
|
7 |
|
->requiresAtLeastOneElement() |
|
|
|
|
|
|
83
|
7 |
|
->useAttributeAsKey('name') |
|
84
|
7 |
|
->arrayPrototype() |
|
85
|
7 |
|
->isRequired() |
|
86
|
7 |
|
->beforeNormalization() |
|
87
|
7 |
|
->ifString() |
|
88
|
7 |
|
->then(static function ($v) { |
|
89
|
1 |
|
return ['url' => $v]; |
|
90
|
7 |
|
}) |
|
91
|
7 |
|
->end() |
|
92
|
7 |
|
; |
|
93
|
|
|
|
|
94
|
7 |
|
$this->configureDbalDriverNode($connectionNode); |
|
95
|
7 |
|
$this->configureConfigurationNode($connectionNode, false); |
|
96
|
|
|
|
|
97
|
7 |
|
$connectionNode |
|
98
|
7 |
|
->children() |
|
99
|
7 |
|
->scalarNode('driver')->end() |
|
100
|
7 |
|
->scalarNode('platform_service')->end() |
|
101
|
7 |
|
->scalarNode('server_version')->end() |
|
102
|
7 |
|
->scalarNode('driver_class')->end() |
|
103
|
7 |
|
->scalarNode('wrapper_class')->end() |
|
104
|
7 |
|
->arrayNode('options') |
|
105
|
7 |
|
->useAttributeAsKey('key') |
|
106
|
7 |
|
->variablePrototype()->end() |
|
107
|
7 |
|
->end() |
|
108
|
7 |
|
->arrayNode('default_table_options') |
|
109
|
7 |
|
->info("This option is used by the schema-tool and affects generated SQL. Possible keys include 'charset','collate', and 'engine'.") |
|
110
|
7 |
|
->useAttributeAsKey('name') |
|
111
|
7 |
|
->scalarPrototype()->end() |
|
112
|
7 |
|
->end() |
|
113
|
7 |
|
->append($this->getPlatformTypesNode()) |
|
114
|
7 |
|
->end(); |
|
115
|
|
|
|
|
116
|
7 |
|
$slaveNode = $connectionNode->children()->arrayNode('read'); |
|
117
|
|
|
|
|
118
|
7 |
|
$this->configureDbalDriverNode($slaveNode); |
|
119
|
|
|
|
|
120
|
7 |
|
$shardNode = $connectionNode |
|
121
|
7 |
|
->children() |
|
122
|
7 |
|
->scalarNode('shard_choser')->end() |
|
123
|
7 |
|
->scalarNode('distribution_key')->end() |
|
124
|
7 |
|
->arrayNode('shards') |
|
125
|
7 |
|
->requiresAtLeastOneElement() |
|
126
|
7 |
|
->useAttributeAsKey('name') |
|
127
|
7 |
|
->arrayPrototype(); |
|
128
|
|
|
|
|
129
|
7 |
|
$this->configureDbalDriverNode($shardNode); |
|
130
|
|
|
|
|
131
|
7 |
|
return $root; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Adds config keys related to params processed by the DBAL drivers. |
|
136
|
|
|
* |
|
137
|
|
|
* These keys are available for slave configurations too. |
|
138
|
|
|
*/ |
|
139
|
7 |
|
private function configureDbalDriverNode(ArrayNodeDefinition $node): void |
|
140
|
|
|
{ |
|
141
|
7 |
|
$node |
|
142
|
7 |
|
->children() |
|
143
|
7 |
|
->scalarNode('url')->info('A URL with connection information; any parameter value parsed from this string will override explicitly set parameters')->end() |
|
144
|
7 |
|
->scalarNode('dbname')->end() |
|
|
|
|
|
|
145
|
7 |
|
->scalarNode('host')->end() |
|
146
|
7 |
|
->scalarNode('port')->end() |
|
147
|
7 |
|
->scalarNode('user')->end() |
|
148
|
7 |
|
->scalarNode('password')->end() |
|
149
|
7 |
|
->scalarNode('application_name')->end() |
|
150
|
7 |
|
->scalarNode('charset')->end() |
|
151
|
7 |
|
->scalarNode('path')->end() |
|
152
|
7 |
|
->booleanNode('memory')->end() |
|
153
|
7 |
|
->scalarNode('unix_socket')->info('The unix socket to use for MySQL')->end() |
|
154
|
7 |
|
->booleanNode('persistent')->info('True to use as persistent connection for the ibm_db2 driver')->end() |
|
155
|
7 |
|
->scalarNode('protocol')->info('The protocol to use for the ibm_db2 driver (default to TCPIP if omitted)')->end() |
|
156
|
7 |
|
->booleanNode('service') |
|
157
|
7 |
|
->info('True to use SERVICE_NAME as connection parameter instead of SID for Oracle') |
|
158
|
7 |
|
->end() |
|
159
|
7 |
|
->scalarNode('servicename') |
|
160
|
7 |
|
->info( |
|
161
|
7 |
|
'Overrules dbname parameter if given and used as SERVICE_NAME or SID connection parameter '. |
|
162
|
7 |
|
'for Oracle depending on the service parameter.' |
|
163
|
7 |
|
) |
|
164
|
7 |
|
->end() |
|
165
|
7 |
|
->scalarNode('sessionMode') |
|
166
|
7 |
|
->info('The session mode to use for the oci8 driver') |
|
167
|
7 |
|
->end() |
|
168
|
7 |
|
->scalarNode('server') |
|
169
|
7 |
|
->info('The name of a running database server to connect to for SQL Anywhere.') |
|
170
|
7 |
|
->end() |
|
171
|
7 |
|
->scalarNode('default_dbname') |
|
172
|
7 |
|
->info( |
|
173
|
7 |
|
'Override the default database (postgres) to connect to for PostgreSQL connexion.' |
|
174
|
7 |
|
) |
|
175
|
7 |
|
->end() |
|
176
|
7 |
|
->scalarNode('sslmode') |
|
177
|
7 |
|
->info( |
|
178
|
7 |
|
'Determines whether or with what priority a SSL TCP/IP connection will be negotiated with '. |
|
179
|
7 |
|
'the server for PostgreSQL.' |
|
180
|
7 |
|
) |
|
181
|
7 |
|
->end() |
|
182
|
7 |
|
->scalarNode('sslrootcert') |
|
183
|
7 |
|
->info( |
|
184
|
7 |
|
'The name of a file containing SSL certificate authority (CA) certificate(s). '. |
|
185
|
7 |
|
'If the file exists, the server\'s certificate will be verified to be signed by one of these authorities.' |
|
186
|
7 |
|
) |
|
187
|
7 |
|
->end() |
|
188
|
7 |
|
->scalarNode('sslcert') |
|
189
|
7 |
|
->info( |
|
190
|
7 |
|
'The path to the SSL client certificate file for PostgreSQL.' |
|
191
|
7 |
|
) |
|
192
|
7 |
|
->end() |
|
193
|
7 |
|
->scalarNode('sslkey') |
|
194
|
7 |
|
->info( |
|
195
|
7 |
|
'The path to the SSL client key file for PostgreSQL.' |
|
196
|
7 |
|
) |
|
197
|
7 |
|
->end() |
|
198
|
7 |
|
->scalarNode('sslcrl') |
|
199
|
7 |
|
->info( |
|
200
|
7 |
|
'The file name of the SSL certificate revocation list for PostgreSQL.' |
|
201
|
7 |
|
) |
|
202
|
7 |
|
->end() |
|
203
|
7 |
|
->booleanNode('pooled')->info('True to use a pooled server with the oci8/pdo_oracle driver')->end() |
|
204
|
7 |
|
->booleanNode('MultipleActiveResultSets')->info('Configuring MultipleActiveResultSets for the pdo_sqlsrv driver')->end() |
|
205
|
7 |
|
// ->booleanNode('use_savepoints')->info('Use savepoints for nested transactions')->end() |
|
206
|
7 |
|
->scalarNode('instancename') |
|
207
|
7 |
|
->info( |
|
208
|
7 |
|
'Optional parameter, complete whether to add the INSTANCE_NAME parameter in the connection.'. |
|
209
|
7 |
|
' It is generally used to connect to an Oracle RAC server to select the name'. |
|
210
|
7 |
|
' of a particular instance.' |
|
211
|
7 |
|
) |
|
212
|
7 |
|
->end() |
|
213
|
7 |
|
->scalarNode('connectstring') |
|
214
|
7 |
|
->info( |
|
215
|
7 |
|
'Complete Easy Connect connection descriptor, see https://docs.oracle.com/database/121/NETAG/naming.htm.'. |
|
216
|
7 |
|
'When using this option, you will still need to provide the user and password parameters, but the other '. |
|
217
|
7 |
|
'parameters will no longer be used. Note that when using this parameter, the getHost and getPort methods'. |
|
218
|
7 |
|
' from Doctrine\DBAL\Connection will no longer function as expected.' |
|
219
|
7 |
|
) |
|
220
|
7 |
|
->end() |
|
221
|
7 |
|
->end() |
|
222
|
7 |
|
->beforeNormalization() |
|
223
|
7 |
|
->ifTrue(static function ($v) { |
|
224
|
7 |
|
return !isset($v['sessionMode']) && isset($v['session_mode']); |
|
225
|
7 |
|
}) |
|
226
|
7 |
|
->then(static function ($v) { |
|
227
|
|
|
$v['sessionMode'] = $v['session_mode']; |
|
228
|
|
|
unset($v['session_mode']); |
|
229
|
|
|
|
|
230
|
|
|
return $v; |
|
231
|
7 |
|
}) |
|
232
|
7 |
|
->end() |
|
233
|
7 |
|
->beforeNormalization() |
|
234
|
7 |
|
->ifTrue(static function ($v) { |
|
235
|
7 |
|
return !isset($v['MultipleActiveResultSets']) && isset($v['multiple_active_result_sets']); |
|
236
|
7 |
|
}) |
|
237
|
7 |
|
->then(static function ($v) { |
|
238
|
|
|
$v['MultipleActiveResultSets'] = $v['multiple_active_result_sets']; |
|
239
|
|
|
unset($v['multiple_active_result_sets']); |
|
240
|
|
|
|
|
241
|
|
|
return $v; |
|
242
|
7 |
|
}) |
|
243
|
7 |
|
->end(); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* @return NodeDefinition |
|
248
|
|
|
*/ |
|
249
|
7 |
|
private function getTypesNode() |
|
250
|
|
|
{ |
|
251
|
7 |
|
$root = (new TreeBuilder('types'))->getRootNode(); |
|
252
|
7 |
|
$root |
|
253
|
7 |
|
->useAttributeAsKey('name') |
|
|
|
|
|
|
254
|
7 |
|
->arrayPrototype() |
|
255
|
7 |
|
->beforeNormalization() |
|
256
|
7 |
|
->ifString() |
|
257
|
7 |
|
->then(static function ($v) { |
|
258
|
|
|
return ['class' => $v]; |
|
259
|
7 |
|
}) |
|
260
|
7 |
|
->end() |
|
261
|
7 |
|
->children() |
|
262
|
7 |
|
->scalarNode('class')->isRequired()->end() |
|
263
|
7 |
|
->end() |
|
264
|
7 |
|
; |
|
265
|
|
|
|
|
266
|
7 |
|
return $root; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* @return NodeDefinition |
|
271
|
|
|
*/ |
|
272
|
7 |
|
private function getPlatformTypesNode() |
|
273
|
|
|
{ |
|
274
|
7 |
|
$root = (new TreeBuilder('platformTypes'))->getRootNode(); |
|
275
|
7 |
|
$root |
|
276
|
7 |
|
->useAttributeAsKey('name') |
|
277
|
7 |
|
->arrayPrototype() |
|
278
|
7 |
|
->beforeNormalization() |
|
279
|
7 |
|
->ifString() |
|
280
|
7 |
|
->then(static function ($v) { |
|
281
|
|
|
return ['class' => $v]; |
|
282
|
7 |
|
}) |
|
283
|
7 |
|
->end() |
|
284
|
7 |
|
->children() |
|
285
|
7 |
|
->scalarNode('class')->isRequired()->end() |
|
286
|
7 |
|
->end() |
|
287
|
7 |
|
->beforeNormalization() |
|
288
|
7 |
|
->ifTrue(function ($value) { return !empty($value) && !method_exists(PrimeConfiguration::class, 'addPlatformType'); }) |
|
289
|
7 |
|
->thenInvalid('Define platform types is only supported by bdf-prime version >= 2.1') |
|
290
|
7 |
|
; |
|
291
|
|
|
|
|
292
|
7 |
|
return $root; |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
/** |
|
296
|
|
|
* @return NodeDefinition |
|
297
|
|
|
*/ |
|
298
|
7 |
|
private function getMigrationNode() |
|
299
|
|
|
{ |
|
300
|
7 |
|
$root = (new TreeBuilder('migration'))->getRootNode(); |
|
301
|
7 |
|
$root->children() |
|
302
|
7 |
|
->scalarNode('path') |
|
303
|
7 |
|
->info('The directory path where the migration file will be stored.') |
|
304
|
7 |
|
->isRequired() |
|
305
|
7 |
|
->end() |
|
306
|
7 |
|
->scalarNode('connection') |
|
307
|
7 |
|
->info('The prime connection name to use to access to the version of migrations.') |
|
308
|
7 |
|
->defaultNull() |
|
309
|
7 |
|
->end() |
|
310
|
7 |
|
->scalarNode('table') |
|
311
|
7 |
|
->info('The table name to store the version of migrations. The default name is "migrations".') |
|
312
|
7 |
|
->defaultValue('migrations') |
|
313
|
7 |
|
->end() |
|
314
|
7 |
|
; |
|
315
|
|
|
|
|
316
|
7 |
|
return $root; |
|
317
|
|
|
} |
|
318
|
|
|
|
|
319
|
|
|
/** |
|
320
|
|
|
* @return NodeDefinition |
|
321
|
|
|
*/ |
|
322
|
7 |
|
private function getCacheNode() |
|
323
|
|
|
{ |
|
324
|
7 |
|
$root = (new TreeBuilder('cache'))->getRootNode(); |
|
325
|
7 |
|
$root->children() |
|
326
|
7 |
|
->arrayNode('query') |
|
327
|
7 |
|
->info('The result cache service. Should implement Bdf\Prime\Cache\CacheInterface.') |
|
328
|
7 |
|
->children() |
|
329
|
7 |
|
->scalarNode('pool')->end() |
|
330
|
7 |
|
->scalarNode('service')->end() |
|
331
|
7 |
|
->end() |
|
332
|
7 |
|
->end() |
|
333
|
7 |
|
->arrayNode('metadata') |
|
334
|
7 |
|
->info('The metadata cache service. Should implement Psr\SimpleCache\CacheInterface.') |
|
335
|
7 |
|
->children() |
|
336
|
7 |
|
->scalarNode('pool')->end() |
|
337
|
7 |
|
->scalarNode('service')->end() |
|
338
|
7 |
|
->end() |
|
339
|
7 |
|
->end() |
|
340
|
7 |
|
; |
|
341
|
|
|
|
|
342
|
7 |
|
return $root; |
|
343
|
|
|
} |
|
344
|
|
|
} |
|
345
|
|
|
|