|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* neuralyzer : Data Anonymization Library and CLI Tool |
|
4
|
|
|
* |
|
5
|
|
|
* PHP Version 7.1 |
|
6
|
|
|
* |
|
7
|
|
|
* @author Emmanuel Dyan |
|
8
|
|
|
* @author Rémi Sauvat |
|
9
|
|
|
* @copyright 2018 Emmanuel Dyan |
|
10
|
|
|
* |
|
11
|
|
|
* @package edyan/neuralyzer |
|
12
|
|
|
* |
|
13
|
|
|
* @license GNU General Public License v2.0 |
|
14
|
|
|
* |
|
15
|
|
|
* @link https://github.com/edyan/neuralyzer |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace Edyan\Neuralyzer\Configuration; |
|
19
|
|
|
|
|
20
|
|
|
use Edyan\Neuralyzer\Guesser; |
|
21
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
22
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Configuration Validation |
|
26
|
|
|
*/ |
|
27
|
|
|
class ConfigDefinition implements ConfigurationInterface |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Validate the configuration |
|
31
|
|
|
* |
|
32
|
|
|
* The config structure is something like : |
|
33
|
|
|
* ## Root |
|
34
|
|
|
* entities: |
|
35
|
|
|
* ## Can be repeated : the name of the table, is an array |
|
36
|
|
|
* accounts: |
|
37
|
|
|
* cols: |
|
38
|
|
|
* ## Can be repeated : the name of the field, is an array |
|
39
|
|
|
* name: |
|
40
|
|
|
* method: words # Required: name of the method |
|
41
|
|
|
* params: [8] # Optional: parameters (an array) |
|
42
|
|
|
* |
|
43
|
|
|
* @return TreeBuilder |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getConfigTreeBuilder() |
|
46
|
|
|
{ |
|
47
|
|
|
$treeBuilder = new TreeBuilder(); |
|
48
|
|
|
$rootNode = $treeBuilder->root('config'); |
|
49
|
|
|
$rootNode |
|
50
|
|
|
->children() |
|
51
|
|
|
->scalarNode('guesser') |
|
52
|
|
|
->info('Set the guesser class') |
|
53
|
|
|
->defaultValue(Guesser::class) |
|
54
|
|
|
->cannotBeEmpty() |
|
55
|
|
|
->end() |
|
56
|
|
|
->scalarNode('guesser_version') |
|
57
|
|
|
->info('Set the version of the guesser the conf has been written with') |
|
58
|
|
|
->defaultValue((new Guesser)->getVersion()) |
|
59
|
|
|
->cannotBeEmpty() |
|
60
|
|
|
->end() |
|
61
|
|
|
->scalarNode('language') |
|
62
|
|
|
->info("Faker's language, make sure all your methods have a translation") |
|
63
|
|
|
->defaultValue('en_US') |
|
64
|
|
|
->end() |
|
65
|
|
|
->arrayNode('entities') |
|
66
|
|
|
->info("List all entities, theirs cols and actions") |
|
67
|
|
|
->example('people') |
|
68
|
|
|
->isRequired() |
|
69
|
|
|
->requiresAtLeastOneElement() |
|
70
|
|
|
->prototype('array') |
|
71
|
|
|
->children() |
|
72
|
|
|
->scalarNode('action') |
|
73
|
|
|
->info('Either "update" or "insert" data') |
|
74
|
|
|
->defaultValue('update') |
|
75
|
|
|
->validate() |
|
76
|
|
|
->ifNotInArray(['update', 'insert']) |
|
77
|
|
|
->thenInvalid('Action is either "update" or "insert"') |
|
78
|
|
|
->end() |
|
79
|
|
|
->end() |
|
80
|
|
|
->scalarNode('delete') |
|
81
|
|
|
->info('Should we delete data with what is defined in "delete_where" ?') |
|
82
|
|
|
->defaultValue(false) |
|
83
|
|
|
->end() |
|
84
|
|
|
->scalarNode('delete_where') |
|
85
|
|
|
->cannotBeEmpty() |
|
86
|
|
|
->info('Condition applied in a WHERE if delete is set to "true"') |
|
87
|
|
|
->example("'1 = 1'") |
|
88
|
|
|
->end() |
|
89
|
|
|
->arrayNode('cols') |
|
90
|
|
|
->example([ |
|
91
|
|
|
'first_name' => ['method' => 'firstName'], |
|
92
|
|
|
'last_name' => ['method' => 'lastName'] |
|
93
|
|
|
]) |
|
94
|
|
|
->requiresAtLeastOneElement() |
|
95
|
|
|
->prototype('array') |
|
96
|
|
|
->children() |
|
97
|
|
|
->scalarNode('method')->isRequired()->end() |
|
98
|
|
|
->arrayNode('params') |
|
99
|
|
|
->defaultValue([]) |
|
100
|
|
|
->prototype('variable')->end() |
|
101
|
|
|
->end() |
|
102
|
|
|
->end() |
|
103
|
|
|
->end() |
|
104
|
|
|
->end() |
|
105
|
|
|
->end() |
|
106
|
|
|
->end() |
|
107
|
|
|
->end() |
|
108
|
|
|
->end() |
|
109
|
|
|
; |
|
110
|
|
|
|
|
111
|
|
|
return $treeBuilder; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|