1 | <?php |
||
8 | class Anonymizer |
||
9 | { |
||
10 | /** |
||
11 | * Database interactions object. |
||
12 | * |
||
13 | * @var DatabaseInterface |
||
14 | */ |
||
15 | protected $database; |
||
16 | |||
17 | /** |
||
18 | * Generator object (e.g \Faker\Factory). |
||
19 | * |
||
20 | * @var mixed |
||
21 | */ |
||
22 | protected $generator; |
||
23 | |||
24 | /** |
||
25 | * Blueprints for tables. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $blueprints = []; |
||
30 | |||
31 | /** |
||
32 | * Constructor. |
||
33 | * |
||
34 | * @param DatabaseInterface $database |
||
35 | * @param mixed $generator |
||
36 | */ |
||
37 | public function __construct(DatabaseInterface $database, $generator = null) |
||
49 | |||
50 | /** |
||
51 | * Setter for generator. |
||
52 | * |
||
53 | * @param mixed $generator |
||
54 | * |
||
55 | * @return $this |
||
56 | */ |
||
57 | public function setGenerator($generator) |
||
63 | |||
64 | /** |
||
65 | * Getter for generator. |
||
66 | * |
||
67 | * @return mixed |
||
68 | */ |
||
69 | public function getGenerator() |
||
73 | |||
74 | /** |
||
75 | * Perform data anonymization. |
||
76 | * |
||
77 | * @return void |
||
78 | */ |
||
79 | public function run() |
||
85 | |||
86 | /** |
||
87 | * Describe a table with a given callback. |
||
88 | * |
||
89 | * @param string $name |
||
90 | * @param callable $callback |
||
91 | * |
||
92 | * @return void |
||
93 | */ |
||
94 | public function table($name, callable $callback) |
||
100 | |||
101 | /** |
||
102 | * Apply blueprint to the database. |
||
103 | * |
||
104 | * @param Blueprint $blueprint |
||
105 | * |
||
106 | * @return void |
||
107 | */ |
||
108 | protected function applyBlueprint(Blueprint $blueprint) |
||
114 | |||
115 | /** |
||
116 | * Update all needed values of a give column. |
||
117 | * |
||
118 | * @param string $table |
||
119 | * @param array $primary |
||
120 | * @param array $column |
||
121 | */ |
||
122 | protected function updateColumn($table, $primary, $column) |
||
136 | |||
137 | /** |
||
138 | * Calculate new value for each row. |
||
139 | * |
||
140 | * @param string|callable $replace |
||
141 | * @param int $rowNum |
||
142 | * |
||
143 | * @return string |
||
144 | */ |
||
145 | protected function calculateNewValue($replace, $rowNum) |
||
151 | |||
152 | /** |
||
153 | * Replace placeholders. |
||
154 | * |
||
155 | * @param mixed $value |
||
156 | * @param int $rowNum |
||
157 | * |
||
158 | * @return mixed |
||
159 | */ |
||
160 | protected function replacePlaceholders($value, $rowNum) |
||
168 | |||
169 | /** |
||
170 | * @param $replace |
||
171 | * |
||
172 | * @return mixed |
||
173 | */ |
||
174 | protected function handlePossibleClosure($replace) |
||
186 | |||
187 | /** |
||
188 | * Merge columns for select. |
||
189 | * |
||
190 | * @param array $primary |
||
191 | * @param string $columnName |
||
192 | * |
||
193 | * @return array |
||
194 | */ |
||
195 | protected function mergeColumns($primary, $columnName) |
||
201 | } |
||
202 |