1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Elimuswift\DbExporter\Commands; |
4
|
|
|
|
5
|
|
|
use Config; |
6
|
|
|
use Illuminate\Console\Command; |
7
|
|
|
use Elimuswift\DbExporter\DbExporter; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
10
|
|
|
|
11
|
|
|
class GeneratorCommand extends Command |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Current database being exported or migrated. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
**/ |
18
|
|
|
protected $database; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Get the database name from the app/config/database.php file. |
22
|
|
|
* |
23
|
|
|
* @return string |
24
|
|
|
*/ |
25
|
|
|
protected function getDatabaseName() |
26
|
|
|
{ |
27
|
|
|
$connType = Config::get('database.default'); |
28
|
|
|
$database = Config::get('database.connections.' . $connType); |
29
|
|
|
|
30
|
|
|
return $database['database']; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
//end getDatabaseName() |
34
|
|
|
|
35
|
|
|
protected function blockMessage($title, $message, $style = 'info') |
36
|
|
|
{ |
37
|
|
|
// Symfony style block messages |
38
|
|
|
$formatter = $this->getHelperSet()->get('formatter'); |
39
|
|
|
$errorMessages = [ |
40
|
|
|
$title, |
41
|
|
|
$message, |
42
|
|
|
]; |
43
|
|
|
$formattedBlock = $formatter->formatBlock($errorMessages, $style, true); |
44
|
|
|
$this->line($formattedBlock); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
//end blockMessage() |
48
|
|
|
|
49
|
|
|
protected function sectionMessage($title, $message) |
50
|
|
|
{ |
51
|
|
|
$formatter = $this->getHelperSet()->get('formatter'); |
52
|
|
|
$formattedLine = $formatter->formatSection( |
53
|
|
|
$title, |
54
|
|
|
$message |
55
|
|
|
); |
56
|
|
|
$this->line($formattedLine); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
//end sectionMessage() |
60
|
|
|
|
61
|
|
|
protected function getArguments() |
62
|
|
|
{ |
63
|
|
|
return [ |
64
|
|
|
[ |
65
|
|
|
'database', |
66
|
|
|
InputArgument::OPTIONAL, |
67
|
|
|
'Override the application database', |
68
|
|
|
], |
69
|
|
|
]; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
//end getArguments() |
73
|
|
|
|
74
|
|
|
protected function getOptions() |
75
|
|
|
{ |
76
|
|
|
return [ |
77
|
|
|
[ |
78
|
|
|
'ignore', |
79
|
|
|
'i', |
80
|
|
|
InputOption::VALUE_REQUIRED, |
81
|
|
|
'Ignore tables to export, seperated by a comma', |
82
|
|
|
null, |
83
|
|
|
], |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
//end getOptions() |
88
|
|
|
|
89
|
|
|
protected function fireAction($action, $database) |
90
|
|
|
{ |
91
|
|
|
// Grab the options |
92
|
|
|
$ignore = $this->option('ignore'); |
93
|
|
|
$this->database = $database; |
94
|
|
|
if (empty($ignore)) { |
95
|
|
|
$this->handler->$action($database); |
|
|
|
|
96
|
|
|
} else { |
97
|
|
|
$tables = explode(',', str_replace(' ', '', $ignore)); |
98
|
|
|
DbExporter::$ignore = array_merge(DbExporter::$ignore, $tables); |
99
|
|
|
$this->handler->$action($database); |
100
|
|
|
foreach ($tables as $table) { |
101
|
|
|
$this->comment("Ignoring the {$table} table"); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
//end fireAction() |
107
|
|
|
}//end class |
108
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: