1 | <?php |
||
29 | abstract class AbstractAnonymizer |
||
30 | { |
||
31 | /** |
||
32 | * Truncate table |
||
33 | */ |
||
34 | const TRUNCATE_TABLE = 1; |
||
35 | |||
36 | /** |
||
37 | * Update data into table |
||
38 | */ |
||
39 | const UPDATE_TABLE = 2; |
||
40 | |||
41 | /** |
||
42 | * Insert data into table |
||
43 | */ |
||
44 | const INSERT_TABLE = 4; |
||
45 | |||
46 | |||
47 | /** |
||
48 | * Set the batch size for updates |
||
49 | * @var int |
||
50 | */ |
||
51 | protected $batchSize = 1000; |
||
52 | |||
53 | /** |
||
54 | * Contains the configuration object |
||
55 | * @var Reader |
||
56 | */ |
||
57 | protected $configuration; |
||
58 | |||
59 | /** |
||
60 | * Configuration of entities |
||
61 | * @var array |
||
62 | */ |
||
63 | protected $configEntites = []; |
||
64 | |||
65 | /** |
||
66 | * Current table (entity) to process |
||
67 | * @var string |
||
68 | */ |
||
69 | protected $entity; |
||
70 | |||
71 | /** |
||
72 | * Current table (entity) Columns |
||
73 | * @var array |
||
74 | */ |
||
75 | protected $entityCols; |
||
76 | |||
77 | /** |
||
78 | * Limit the number of updates or create |
||
79 | * @var int |
||
80 | */ |
||
81 | protected $limit = 0; |
||
82 | |||
83 | /** |
||
84 | * Pretend we do the update, but do nothing |
||
85 | * @var bool |
||
86 | */ |
||
87 | protected $pretend = true; |
||
88 | |||
89 | /** |
||
90 | * Return the generated SQL |
||
91 | * @var bool |
||
92 | */ |
||
93 | protected $returnRes = false; |
||
94 | |||
95 | |||
96 | /** |
||
97 | 20 | * Process the entity according to the anonymizer type |
|
98 | * @param string $entity Entity's name |
||
99 | 20 | * @param callable|null $callback Callback function with current row num as parameter |
|
100 | 20 | * @return array |
|
101 | 20 | */ |
|
102 | abstract public function processEntity( |
||
106 | |||
107 | |||
108 | /** |
||
109 | 16 | * Set the configuration |
|
110 | * @param Reader $configuration |
||
111 | 16 | */ |
|
112 | public function setConfiguration(Reader $configuration): void |
||
117 | 4 | ||
118 | |||
119 | /** |
||
120 | 14 | * Limit of fake generated records for updates and creates |
|
121 | 14 | * @param int $limit |
|
122 | 14 | * @return DB |
|
123 | 11 | */ |
|
124 | 11 | public function setLimit(int $limit): DB |
|
133 | |||
134 | |||
135 | /** |
||
136 | * Activate or deactivate the pretending mode (dry run) |
||
137 | * @param bool $pretend |
||
138 | * @return DB |
||
139 | */ |
||
140 | 4 | public function setPretend(bool $pretend): DB |
|
146 | |||
147 | |||
148 | 3 | /** |
|
149 | * Return or not a result (like an SQL Query that has |
||
150 | * been generated with fake data) |
||
151 | * @param bool $returnRes |
||
152 | * @return DB |
||
153 | */ |
||
154 | public function setReturnRes(bool $returnRes): DB |
||
160 | |||
161 | 12 | ||
162 | /** |
||
163 | 12 | * Evaluate, from the configuration if I have to update or Truncate the table |
|
164 | 12 | * |
|
165 | 12 | * @return int |
|
166 | 12 | */ |
|
167 | 11 | protected function whatToDoWithEntity(): int |
|
191 | |||
192 | |||
193 | /** |
||
194 | * Returns the 'delete_where' parameter for an entity in config (or empty) |
||
195 | 16 | * |
|
196 | * @return string |
||
197 | 16 | */ |
|
198 | 1 | public function getWhereConditionInConfig(): string |
|
208 | |||
209 | |||
210 | /** |
||
211 | * Generate fake data for an entity and return it as an Array |
||
212 | * |
||
213 | * @return array |
||
214 | */ |
||
215 | 12 | protected function generateFakeData(): array |
|
246 | |||
247 | |||
248 | /** |
||
249 | * Make sure that entity is defined in the configuration |
||
250 | * |
||
251 | * @throws NeuralizerConfigurationException |
||
252 | */ |
||
253 | private function checkEntityIsInConfig(): void |
||
266 | |||
267 | /** |
||
268 | * Verify a column is defined in the real entityCols |
||
269 | * |
||
270 | * @throws NeuralizerConfigurationException |
||
271 | * @param string $colName [description] |
||
272 | */ |
||
273 | private function checkColIsInEntity(string $colName): void |
||
279 | } |
||
280 |