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
|
26 |
|
public function getConfigTreeBuilder() |
46
|
|
|
{ |
47
|
26 |
|
$treeBuilder = new TreeBuilder(); |
48
|
26 |
|
$rootNode = $treeBuilder->root('config'); |
49
|
|
|
$rootNode |
50
|
26 |
|
->children() |
51
|
26 |
|
->scalarNode('guesser') |
52
|
26 |
|
->info('Set the guesser class') |
53
|
26 |
|
->defaultValue(Guesser::class) |
54
|
26 |
|
->cannotBeEmpty() |
55
|
26 |
|
->end() |
56
|
26 |
|
->scalarNode('guesser_version') |
57
|
26 |
|
->info('Set the version of the guesser the conf has been written with') |
58
|
26 |
|
->defaultValue((new Guesser)->getVersion()) |
59
|
26 |
|
->cannotBeEmpty() |
60
|
26 |
|
->end() |
61
|
26 |
|
->scalarNode('language') |
62
|
26 |
|
->info("Faker's language, make sure all your methods have a translation") |
63
|
26 |
|
->defaultValue('en_US') |
64
|
26 |
|
->end() |
65
|
26 |
|
->arrayNode('entities') |
66
|
26 |
|
->info("List all entities, theirs cols and actions") |
67
|
26 |
|
->example('people') |
68
|
26 |
|
->isRequired() |
69
|
26 |
|
->requiresAtLeastOneElement() |
70
|
26 |
|
->prototype('array') |
71
|
26 |
|
->children() |
72
|
26 |
|
->scalarNode('action') |
73
|
26 |
|
->info('Either "update" or "insert" data') |
74
|
26 |
|
->defaultValue('update') |
75
|
26 |
|
->validate() |
76
|
26 |
|
->ifNotInArray(['update', 'insert']) |
77
|
26 |
|
->thenInvalid('Action is either "update" or "insert"') |
78
|
26 |
|
->end() |
79
|
26 |
|
->end() |
80
|
26 |
|
->scalarNode('delete') |
81
|
26 |
|
->info('Should we delete data with what is defined in "delete_where" ?') |
82
|
26 |
|
->defaultValue(false) |
83
|
26 |
|
->end() |
84
|
26 |
|
->scalarNode('delete_where') |
85
|
26 |
|
->cannotBeEmpty() |
86
|
26 |
|
->info('Condition applied in a WHERE if delete is set to "true"') |
87
|
26 |
|
->example("'1 = 1'") |
88
|
26 |
|
->end() |
89
|
26 |
|
->arrayNode('cols') |
90
|
26 |
|
->example([ |
91
|
26 |
|
'first_name' => ['method' => 'firstName'], |
92
|
|
|
'last_name' => ['method' => 'lastName'] |
93
|
|
|
]) |
94
|
26 |
|
->requiresAtLeastOneElement() |
95
|
26 |
|
->prototype('array') |
96
|
26 |
|
->children() |
97
|
26 |
|
->scalarNode('method')->isRequired()->end() |
98
|
26 |
|
->arrayNode('params') |
99
|
26 |
|
->defaultValue([]) |
100
|
26 |
|
->prototype('variable')->end() |
101
|
26 |
|
->end() |
102
|
26 |
|
->end() |
103
|
26 |
|
->end() |
104
|
26 |
|
->end() |
105
|
26 |
|
->end() |
106
|
26 |
|
->end() |
107
|
26 |
|
->end() |
108
|
26 |
|
->end() |
109
|
|
|
; |
110
|
|
|
|
111
|
26 |
|
return $treeBuilder; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|