1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Arrilot\LaravelDataAnonymization\Commands;
|
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command;
|
6
|
|
|
use Illuminate\Filesystem\Filesystem;
|
7
|
|
|
use Illuminate\Support\Composer;
|
8
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
9
|
|
|
|
10
|
|
|
class AnonymizationInstallCommand extends Command
|
11
|
|
|
{
|
12
|
|
|
/**
|
13
|
|
|
* The console command name.
|
14
|
|
|
*
|
15
|
|
|
* @var string
|
16
|
|
|
*/
|
17
|
|
|
protected $name = 'anonymization:install';
|
18
|
|
|
|
19
|
|
|
/**
|
20
|
|
|
* The console command description.
|
21
|
|
|
*
|
22
|
|
|
* @var string
|
23
|
|
|
*/
|
24
|
|
|
protected $description = 'Install anonymization boilerplate';
|
25
|
|
|
|
26
|
|
|
/**
|
27
|
|
|
* The Composer instance.
|
28
|
|
|
*
|
29
|
|
|
* @var Filesystem
|
30
|
|
|
*/
|
31
|
|
|
protected $files;
|
32
|
|
|
|
33
|
|
|
/**
|
34
|
|
|
* The Composer instance.
|
35
|
|
|
*
|
36
|
|
|
* @var Composer
|
37
|
|
|
*/
|
38
|
|
|
protected $composer;
|
39
|
|
|
|
40
|
|
|
/**
|
41
|
|
|
* Constructor.
|
42
|
|
|
*
|
43
|
|
|
* @param Filesystem $files
|
44
|
|
|
* @param Composer $composer
|
45
|
|
|
*/
|
46
|
|
|
public function __construct(Filesystem $files, Composer $composer)
|
47
|
|
|
{
|
48
|
|
|
parent::__construct();
|
49
|
|
|
|
50
|
|
|
$this->files = $files;
|
51
|
|
|
$this->composer = $composer;
|
52
|
|
|
}
|
53
|
|
|
|
54
|
|
|
public function handle()
|
55
|
|
|
{
|
56
|
|
|
return $this->fire();
|
57
|
|
|
}
|
58
|
|
|
|
59
|
|
|
/**
|
60
|
|
|
* Execute the console command.
|
61
|
|
|
*
|
62
|
|
|
* @return void
|
63
|
|
|
*/
|
64
|
|
|
public function fire()
|
65
|
|
|
{
|
66
|
|
|
$dir = $this->laravel->databasePath() . '/anonymization';
|
|
|
|
|
67
|
|
|
|
68
|
|
|
$this->createDirectory($dir);
|
69
|
|
|
$this->createAnonymizer($dir, 'DatabaseAnonymizer');
|
70
|
|
|
$this->createAnonymizer($dir, 'UserTableAnonymizer');
|
71
|
|
|
|
72
|
|
|
$this->composer->dumpAutoloads();
|
73
|
|
|
|
74
|
|
|
$this->info("Installation completed");
|
75
|
|
|
|
76
|
|
|
}
|
77
|
|
|
|
78
|
|
|
/**
|
79
|
|
|
* Create directory for anonymizers.
|
80
|
|
|
*
|
81
|
|
|
* @param string $dir
|
82
|
|
|
*/
|
83
|
|
|
protected function createDirectory($dir)
|
84
|
|
|
{
|
85
|
|
|
if ($this->files->isDirectory($dir)) {
|
86
|
|
|
$this->error("Directory {$dir} already exists");
|
87
|
|
|
|
88
|
|
|
return;
|
89
|
|
|
}
|
90
|
|
|
|
91
|
|
|
$this->files->makeDirectory($dir);
|
92
|
|
|
}
|
93
|
|
|
|
94
|
|
|
/**
|
95
|
|
|
* Create Anonymizer class.
|
96
|
|
|
*
|
97
|
|
|
* @param string $dir
|
98
|
|
|
*
|
99
|
|
|
* @return void
|
100
|
|
|
*/
|
101
|
|
|
protected function createAnonymizer($dir, $class)
|
102
|
|
|
{
|
103
|
|
|
$path = "{$dir}/{$class}.php";
|
104
|
|
|
|
105
|
|
|
if ($this->files->exists($path)) {
|
106
|
|
|
$this->error("File {$path} already exists");
|
107
|
|
|
|
108
|
|
|
return;
|
109
|
|
|
}
|
110
|
|
|
|
111
|
|
|
$this->files->copy(__DIR__.'/stubs/'.$class.'.stub', $path);
|
112
|
|
|
}
|
113
|
|
|
}
|
114
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.