1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Lamoda\CleanerBundle\DependencyInjection; |
6
|
|
|
|
7
|
|
|
use Lamoda\Cleaner\DB\DoctrineDBALCleaner; |
8
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
9
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
10
|
|
|
|
11
|
|
|
class Configuration implements ConfigurationInterface |
12
|
|
|
{ |
13
|
2 |
|
public function getConfigTreeBuilder() |
14
|
|
|
{ |
15
|
2 |
|
$builder = new TreeBuilder('lamoda_cleaner'); |
16
|
|
|
|
17
|
2 |
|
if (method_exists($builder, 'getRootNode')) { |
18
|
2 |
|
$root = $builder->getRootNode(); |
19
|
|
|
} else { |
20
|
|
|
// BC layer for symfony/config 4.1 and older |
21
|
|
|
$root = $builder->root('lamoda_cleaner'); |
|
|
|
|
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
$root |
25
|
2 |
|
->children() |
26
|
2 |
|
->arrayNode('db') |
27
|
2 |
|
->useAttributeAsKey('name') |
28
|
2 |
|
->arrayPrototype() |
29
|
2 |
|
->info('Cleaner name, specific to your project') |
30
|
2 |
|
->addDefaultsIfNotSet() |
31
|
2 |
|
->beforeNormalization() |
32
|
|
|
->ifTrue(function ($v) { return empty($v['queries']); }) |
33
|
|
|
->then(function ($v) { |
34
|
1 |
|
$result = ['queries' => [$v]]; |
35
|
|
|
|
36
|
1 |
|
$topLevelKeys = ['class', 'transactional', 'dbal_connection']; |
37
|
1 |
|
foreach ($topLevelKeys as $key) { |
38
|
1 |
|
if (array_key_exists($key, $v)) { |
39
|
1 |
|
$result[$key] = $v[$key]; |
40
|
1 |
|
unset($result['queries'][0][$key]); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
1 |
|
return $result; |
45
|
2 |
|
}) |
46
|
2 |
|
->end() |
47
|
2 |
|
->children() |
48
|
2 |
|
->scalarNode('class') |
49
|
2 |
|
->info('Class name') |
50
|
2 |
|
->defaultValue(DoctrineDBALCleaner::class) |
51
|
2 |
|
->cannotBeEmpty() |
52
|
2 |
|
->end() |
53
|
2 |
|
->booleanNode('transactional') |
54
|
2 |
|
->info('Wrap query/queries in transaction') |
55
|
2 |
|
->defaultTrue() |
56
|
2 |
|
->end() |
57
|
2 |
|
->scalarNode('dbal_connection') |
58
|
2 |
|
->info('Reference to Doctrine connection for DoctrineDBALCleaner') |
59
|
2 |
|
->defaultValue('database_connection') |
60
|
2 |
|
->cannotBeEmpty() |
61
|
2 |
|
->end() |
62
|
2 |
|
->arrayNode('queries') |
63
|
2 |
|
->info('One or many queries to execute during cleanup') |
64
|
2 |
|
->isRequired() |
65
|
2 |
|
->cannotBeEmpty() |
66
|
2 |
|
->arrayPrototype() |
67
|
2 |
|
->children() |
68
|
2 |
|
->scalarNode('query') |
69
|
2 |
|
->info('SQL query') |
70
|
2 |
|
->isRequired() |
71
|
2 |
|
->cannotBeEmpty() |
72
|
2 |
|
->end() |
73
|
2 |
|
->arrayNode('parameters') |
74
|
2 |
|
->info('List of key => value parameters for SQL') |
75
|
2 |
|
->useAttributeAsKey('name') |
76
|
2 |
|
->scalarPrototype()->end() |
77
|
2 |
|
->end() |
78
|
2 |
|
->arrayNode('types') |
79
|
2 |
|
->info('List of parameter types if required for special SQL escape') |
80
|
2 |
|
->scalarPrototype()->end() |
81
|
2 |
|
->end() |
82
|
2 |
|
->end() |
83
|
2 |
|
->end() |
84
|
2 |
|
->end() |
85
|
2 |
|
->end() |
86
|
2 |
|
->end() |
87
|
2 |
|
->end(); |
88
|
|
|
|
89
|
2 |
|
return $builder; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.