1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* neuralyzer : Data Anonymization Library and CLI Tool |
7
|
|
|
* |
8
|
|
|
* PHP Version 7.2 |
9
|
|
|
* |
10
|
|
|
* @author Emmanuel Dyan |
11
|
|
|
* @author Rémi Sauvat |
12
|
|
|
* |
13
|
|
|
* @copyright 2020 Emmanuel Dyan |
14
|
|
|
* |
15
|
|
|
* @package edyan/neuralyzer |
16
|
|
|
* |
17
|
|
|
* @license GNU General Public License v2.0 |
18
|
|
|
* |
19
|
|
|
* @link https://github.com/edyan/neuralyzer |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Edyan\Neuralyzer\Configuration; |
23
|
|
|
|
24
|
|
|
use Edyan\Neuralyzer\Guesser; |
25
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
26
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Configuration Validation |
30
|
|
|
*/ |
31
|
|
|
class ConfigDefinition implements ConfigurationInterface |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Validate the configuration |
35
|
|
|
* |
36
|
|
|
* The config structure is something like : |
37
|
|
|
* ## Root |
38
|
|
|
* entities: |
39
|
|
|
* ## Can be repeated : the name of the table, is an array |
40
|
|
|
* accounts: |
41
|
|
|
* cols: |
42
|
|
|
* ## Can be repeated : the name of the field, is an array |
43
|
|
|
* name: |
44
|
|
|
* method: words # Required: name of the method |
45
|
45 |
|
* params: [8] # Optional: parameters (an array) |
46
|
|
|
*/ |
47
|
45 |
|
public function getConfigTreeBuilder(): TreeBuilder |
48
|
45 |
|
{ |
49
|
|
|
$treeBuilder = new TreeBuilder('config'); |
50
|
45 |
|
$treeBuilder |
51
|
45 |
|
->getRootNode() |
52
|
45 |
|
->children() |
53
|
45 |
|
->scalarNode('guesser') |
54
|
45 |
|
->info('Set the guesser class') |
55
|
45 |
|
->defaultValue(Guesser::class) |
56
|
45 |
|
->cannotBeEmpty() |
57
|
45 |
|
->end() |
58
|
45 |
|
->scalarNode('guesser_version') |
59
|
45 |
|
->info('Set the version of the guesser the conf has been written with') |
60
|
45 |
|
->defaultValue((new Guesser())->getVersion()) |
61
|
45 |
|
->cannotBeEmpty() |
62
|
45 |
|
->end() |
63
|
45 |
|
->scalarNode('language') |
64
|
45 |
|
->info("Faker's language, make sure all your methods have a translation") |
65
|
45 |
|
->defaultValue('en_US') |
66
|
45 |
|
->end() |
67
|
45 |
|
->arrayNode('entities') |
68
|
45 |
|
->info('List all entities, theirs cols and actions') |
69
|
45 |
|
->example('people') |
70
|
45 |
|
->isRequired() |
71
|
45 |
|
->requiresAtLeastOneElement() |
72
|
45 |
|
->prototype('array') |
73
|
45 |
|
->children() |
74
|
45 |
|
->scalarNode('action') |
75
|
45 |
|
->info('Either "update" or "insert" data') |
76
|
45 |
|
->defaultValue('update') |
77
|
45 |
|
->validate() |
78
|
45 |
|
->ifNotInArray(['update', 'insert']) |
79
|
45 |
|
->thenInvalid('Action is either "update" or "insert"') |
80
|
45 |
|
->end() |
81
|
45 |
|
->end() |
82
|
45 |
|
->scalarNode('delete') |
83
|
45 |
|
->info('Should we delete data with what is defined in "delete_where" ?') |
84
|
45 |
|
->setDeprecated('delete and delete_where have been deprecated. Use now pre and post_actions') |
85
|
45 |
|
->end() |
86
|
45 |
|
->scalarNode('delete_where') |
87
|
45 |
|
->cannotBeEmpty() |
88
|
45 |
|
->info('Condition applied in a WHERE if delete is set to "true"') |
89
|
45 |
|
->example("'1 = 1'") |
90
|
45 |
|
->setDeprecated('delete and delete_where have been deprecated. Use now pre and post_actions') |
91
|
45 |
|
->end() |
92
|
45 |
|
->arrayNode('cols') |
93
|
45 |
|
->example([ |
94
|
45 |
|
'first_name' => ['method' => 'firstName'], |
95
|
45 |
|
'last_name' => ['method' => 'lastName'], |
96
|
45 |
|
]) |
97
|
45 |
|
->requiresAtLeastOneElement() |
98
|
45 |
|
->prototype('array') |
99
|
|
|
->children() |
100
|
|
|
->scalarNode('method') |
101
|
45 |
|
->isRequired() |
102
|
45 |
|
->info('Faker method to use, see doc : https://github.com/fzaninotto/Faker') |
103
|
45 |
|
->end() |
104
|
45 |
|
->booleanNode('unique') |
105
|
45 |
|
->defaultFalse() |
106
|
45 |
|
->info('Set this option to true to generate unique values for that field (see faker->unique() generator)') |
107
|
45 |
|
->end() |
108
|
45 |
|
->arrayNode('params') |
109
|
45 |
|
->defaultValue([]) |
110
|
45 |
|
->info("Faker's parameters, see Faker's doc") |
111
|
45 |
|
->prototype('variable')->end() |
112
|
45 |
|
->end() |
113
|
45 |
|
->end() |
114
|
45 |
|
->end() |
115
|
45 |
|
->end() |
116
|
45 |
|
->integerNode('limit') |
117
|
45 |
|
->defaultValue(0) |
118
|
45 |
|
->info('Limit the number of written records (update or insert). 100 by default for insert') |
119
|
45 |
|
->min(0) |
120
|
45 |
|
->end() |
121
|
45 |
|
->arrayNode('pre_actions') |
122
|
|
|
->defaultValue([]) |
123
|
|
|
->normalizeKeys(false) |
124
|
45 |
|
->info('The list of expressions language actions to executed before neuralyzing. Be careful that "pretend" has no effect here.') |
125
|
|
|
->prototype('scalar')->end() |
126
|
|
|
->end() |
127
|
|
|
->arrayNode('post_actions') |
128
|
|
|
->defaultValue([]) |
129
|
|
|
->normalizeKeys(false) |
130
|
|
|
->info('The list of expressions language actions to executed after neuralyzing. Be careful that "pretend" has no effect here.') |
131
|
|
|
->prototype('scalar')->end() |
132
|
|
|
->end() |
133
|
|
|
->end() |
134
|
|
|
->end() |
135
|
|
|
->end() |
136
|
|
|
->end() |
137
|
|
|
; |
138
|
|
|
|
139
|
|
|
return $treeBuilder; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|