|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CodexShaper\Dumper\Traits; |
|
4
|
|
|
|
|
5
|
|
|
trait DumperTrait |
|
6
|
|
|
{ |
|
7
|
|
|
/*@var string*/ |
|
8
|
|
|
protected $dbName; |
|
9
|
|
|
/*@var string*/ |
|
10
|
|
|
protected $username; |
|
11
|
|
|
/*@var string*/ |
|
12
|
|
|
protected $password; |
|
13
|
|
|
/*@var string*/ |
|
14
|
|
|
protected $host = 'localhost'; |
|
15
|
|
|
/*@var int*/ |
|
16
|
|
|
protected $port = 3306; |
|
17
|
|
|
/*@var string*/ |
|
18
|
|
|
protected $socket = ''; |
|
19
|
|
|
/*@var string*/ |
|
20
|
|
|
protected $commandBinaryPath = ''; |
|
21
|
|
|
/*@var int*/ |
|
22
|
|
|
protected $timeout = 0; |
|
23
|
|
|
/*@var array*/ |
|
24
|
|
|
protected $tables = []; |
|
25
|
|
|
/*@var array*/ |
|
26
|
|
|
protected $ignoreTables = []; |
|
27
|
|
|
/*@var string*/ |
|
28
|
|
|
protected $destinationPath = 'dump.sql'; |
|
29
|
|
|
/*@var string*/ |
|
30
|
|
|
protected $restorePath = 'dump.sql'; |
|
31
|
|
|
/*@var bool*/ |
|
32
|
|
|
protected $isCompress = false; |
|
33
|
|
|
/*@var string*/ |
|
34
|
|
|
protected $compressCommand = "gzip"; |
|
35
|
|
|
/*@var string*/ |
|
36
|
|
|
protected $compressBinaryPath = ""; |
|
37
|
|
|
/*@var string*/ |
|
38
|
|
|
protected $compressExtension = ".gz"; |
|
39
|
|
|
/*@var bool*/ |
|
40
|
|
|
protected $debug = false; |
|
41
|
|
|
/*@var string*/ |
|
42
|
|
|
protected $command = ""; |
|
43
|
|
|
|
|
44
|
112 |
|
public function setDbName(string $name) |
|
45
|
|
|
{ |
|
46
|
112 |
|
$this->dbName = $name; |
|
47
|
112 |
|
return $this; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
72 |
|
public function setUserName(string $username) |
|
51
|
|
|
{ |
|
52
|
72 |
|
$this->username = $username; |
|
53
|
72 |
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
72 |
|
public function setPassword(string $password) |
|
57
|
|
|
{ |
|
58
|
72 |
|
$this->password = $password; |
|
59
|
72 |
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
4 |
|
public function setHost(string $host) |
|
63
|
|
|
{ |
|
64
|
4 |
|
$this->host = $host; |
|
65
|
4 |
|
return $this; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
6 |
|
public function setPort(int $port) |
|
69
|
|
|
{ |
|
70
|
6 |
|
$this->port = $port; |
|
71
|
6 |
|
return $this; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
4 |
|
public function setSocket(string $socket) |
|
75
|
|
|
{ |
|
76
|
4 |
|
$this->socket = $socket; |
|
77
|
4 |
|
return $this; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function setTimeOut(int $timeout) |
|
81
|
|
|
{ |
|
82
|
|
|
$this->timeout = $timeout; |
|
83
|
|
|
return $this; |
|
84
|
|
|
} |
|
85
|
|
|
/** |
|
86
|
|
|
* @param string|array $tables |
|
87
|
|
|
* @throws \Exception |
|
88
|
|
|
*/ |
|
89
|
12 |
|
public function setTables($tables) |
|
90
|
|
|
{ |
|
91
|
12 |
|
if (!empty($this->ignoreTables)) { |
|
92
|
|
|
throw new \Exception("You can choose only once between tables and ignoreTables at a time"); |
|
93
|
|
|
} |
|
94
|
12 |
|
if (is_string($tables)) { |
|
95
|
4 |
|
$tables = [$tables]; |
|
96
|
|
|
} |
|
97
|
12 |
|
$this->tables = $tables; |
|
98
|
12 |
|
return $this; |
|
99
|
|
|
} |
|
100
|
|
|
/** |
|
101
|
|
|
* @param string|array $tables |
|
102
|
|
|
* @throws \Exception |
|
103
|
|
|
*/ |
|
104
|
12 |
|
public function setIgnoreTables($tables) |
|
105
|
|
|
{ |
|
106
|
12 |
|
if (!empty($this->tables)) { |
|
107
|
4 |
|
throw new \Exception("You can choose only once between tables and ignoreTables at a time"); |
|
108
|
|
|
} |
|
109
|
8 |
|
if (is_string($tables)) { |
|
110
|
4 |
|
$tables = [$tables]; |
|
111
|
|
|
} |
|
112
|
8 |
|
$this->ignoreTables = $tables; |
|
113
|
8 |
|
return $this; |
|
114
|
|
|
} |
|
115
|
12 |
|
public function setCommandBinaryPath(string $path) |
|
116
|
|
|
{ |
|
117
|
12 |
|
$this->commandBinaryPath = $path; |
|
118
|
12 |
|
return $this; |
|
119
|
|
|
} |
|
120
|
76 |
|
public function setDestinationPath(string $path) |
|
121
|
|
|
{ |
|
122
|
76 |
|
$this->destinationPath = $path; |
|
123
|
76 |
|
return $this; |
|
124
|
|
|
} |
|
125
|
32 |
|
public function setRestorePath(string $path) |
|
126
|
|
|
{ |
|
127
|
32 |
|
$this->restorePath = $path; |
|
128
|
32 |
|
return $this; |
|
129
|
|
|
} |
|
130
|
|
|
// Compress |
|
131
|
|
|
public function setCompressBinaryPath(string $path) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->compressBinaryPath = $path; |
|
134
|
|
|
return $this; |
|
135
|
|
|
} |
|
136
|
|
|
public function setCompressCommand(string $command) |
|
137
|
|
|
{ |
|
138
|
|
|
$this->compressCommand = $command; |
|
139
|
|
|
$this->isCompress = true; |
|
140
|
|
|
return $this; |
|
141
|
|
|
} |
|
142
|
|
|
public function setCompressExtension(string $extension) |
|
143
|
|
|
{ |
|
144
|
|
|
$this->compressExtension = $extension; |
|
145
|
|
|
return $this; |
|
146
|
|
|
} |
|
147
|
16 |
|
public function useCompress(string $command = "gzip", string $extension = ".gz", string $binary_path = "") |
|
148
|
|
|
{ |
|
149
|
16 |
|
$this->compressCommand = $command; |
|
150
|
16 |
|
$this->compressExtension = $extension; |
|
151
|
16 |
|
$this->compressBinaryPath = $binary_path; |
|
152
|
16 |
|
$this->isCompress = true; |
|
153
|
|
|
|
|
154
|
16 |
|
return $this; |
|
155
|
|
|
} |
|
156
|
|
|
public function enableDebug() |
|
157
|
|
|
{ |
|
158
|
|
|
$this->debug = true; |
|
159
|
|
|
return $this; |
|
160
|
|
|
} |
|
161
|
|
|
public function getDbName() |
|
162
|
|
|
{ |
|
163
|
|
|
return $this->dbName; |
|
164
|
|
|
} |
|
165
|
|
|
public function getUserName() |
|
166
|
|
|
{ |
|
167
|
|
|
return $this->username; |
|
168
|
|
|
} |
|
169
|
|
|
public function getPassword() |
|
170
|
|
|
{ |
|
171
|
|
|
return $this->password; |
|
172
|
|
|
} |
|
173
|
|
|
public function getHost() |
|
174
|
|
|
{ |
|
175
|
|
|
return $this->host; |
|
176
|
|
|
} |
|
177
|
|
|
public function getPort() |
|
178
|
|
|
{ |
|
179
|
|
|
return $this->port; |
|
180
|
|
|
} |
|
181
|
|
|
public function getSocket() |
|
182
|
|
|
{ |
|
183
|
|
|
return $this->socket; |
|
184
|
|
|
} |
|
185
|
|
|
public function getTimeOut() |
|
186
|
|
|
{ |
|
187
|
|
|
return $this->timeout; |
|
188
|
|
|
} |
|
189
|
|
|
public function getCommandBinaryPath() |
|
190
|
|
|
{ |
|
191
|
|
|
return $this->commandBinaryPath; |
|
192
|
|
|
} |
|
193
|
|
|
public function getDestinationPath() |
|
194
|
|
|
{ |
|
195
|
|
|
return $this->destinationPath; |
|
196
|
|
|
} |
|
197
|
|
|
public function getRestorePath() |
|
198
|
|
|
{ |
|
199
|
|
|
return $this->restorePath; |
|
200
|
|
|
} |
|
201
|
|
|
} |
|
202
|
|
|
|