|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Arrilot\LaravelDataAnonymization; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Arrilot\DataAnonymization\Anonymizer as CoreAnonymizer; |
|
7
|
|
|
|
|
8
|
|
|
abstract class AbstractAnonymizer |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* The console command instance. |
|
12
|
|
|
* |
|
13
|
|
|
* @var \Illuminate\Console\Command |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $command; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Core anonymizer. |
|
19
|
|
|
* |
|
20
|
|
|
* @var \Arrilot\DataAnonymization\Anonymizer |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $core; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* AbstractAnonymizer constructor. |
|
26
|
|
|
* |
|
27
|
|
|
* @param \Arrilot\DataAnonymization\Anonymizer $core |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(CoreAnonymizer $core) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->core = $core; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Run the anonymization. |
|
36
|
|
|
* |
|
37
|
|
|
* @return void |
|
38
|
|
|
*/ |
|
39
|
|
|
abstract public function run(); |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Call selected anonymizer. |
|
43
|
|
|
* |
|
44
|
|
|
* @param string $class |
|
45
|
|
|
* |
|
46
|
|
|
* @return void |
|
47
|
|
|
*/ |
|
48
|
|
|
public function call($class) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->resolve($class)->run(); |
|
51
|
|
|
|
|
52
|
|
|
if (isset($this->command)) { |
|
53
|
|
|
$this->command->getOutput()->writeln("<info>Anonymized:</info> $class"); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Describe a table with a given callback. |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $name |
|
61
|
|
|
* @param callable $callback |
|
62
|
|
|
* |
|
63
|
|
|
* @return void |
|
64
|
|
|
*/ |
|
65
|
|
|
public function table($name, callable $callback) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->core->table($name, $callback); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Set the console command instance. |
|
72
|
|
|
* |
|
73
|
|
|
* @param \Illuminate\Console\Command $command |
|
74
|
|
|
* |
|
75
|
|
|
* @return $this |
|
76
|
|
|
*/ |
|
77
|
|
|
public function setCommand(Command $command) |
|
78
|
|
|
{ |
|
79
|
|
|
$this->command = $command; |
|
80
|
|
|
|
|
81
|
|
|
return $this; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Resolve an instance of the given seeder class. |
|
86
|
|
|
* |
|
87
|
|
|
* @param string $class |
|
88
|
|
|
* |
|
89
|
|
|
* @return AbstractAnonymizer |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function resolve($class) |
|
92
|
|
|
{ |
|
93
|
|
|
$instance = new $class($this->core); |
|
94
|
|
|
|
|
95
|
|
|
if (isset($this->command)) { |
|
96
|
|
|
$instance->setCommand($this->command); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
return $instance; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|