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 string*/ |
32
|
|
|
protected $tempFile = ""; |
33
|
|
|
/*@var bool*/ |
34
|
|
|
protected $isCompress = false; |
35
|
|
|
/*@var string*/ |
36
|
|
|
protected $compressCommand = "gzip"; |
37
|
|
|
/*@var string*/ |
38
|
|
|
protected $compressBinaryPath = ""; |
39
|
|
|
/*@var string*/ |
40
|
|
|
protected $compressExtension = ".gz"; |
41
|
|
|
/*@var bool*/ |
42
|
|
|
protected $debug = false; |
43
|
|
|
/*@var string*/ |
44
|
|
|
protected $command = ""; |
45
|
|
|
|
46
|
16 |
|
public function setDbName(string $name) |
47
|
|
|
{ |
48
|
16 |
|
$this->dbName = $name; |
49
|
16 |
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
16 |
|
public function setUserName(string $username) |
53
|
|
|
{ |
54
|
16 |
|
$this->username = $username; |
55
|
|
|
|
56
|
16 |
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
16 |
|
public function setPassword(string $password) |
60
|
|
|
{ |
61
|
16 |
|
$this->password = $password; |
62
|
|
|
|
63
|
16 |
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function setHost(string $host) |
67
|
|
|
{ |
68
|
|
|
$this->host = $host; |
69
|
|
|
|
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function setPort(int $port) |
74
|
|
|
{ |
75
|
|
|
$this->port = $port; |
76
|
|
|
|
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function setSocket(string $socket) |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
$this->port = $port; |
|
|
|
|
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function setTimeOut(int $timeout) |
88
|
|
|
{ |
89
|
|
|
$this->timeout = $timeout; |
90
|
|
|
|
91
|
|
|
return $this; |
92
|
|
|
} |
93
|
|
|
/** |
94
|
|
|
* @param string|array $tables |
95
|
|
|
* @throws \Exception |
96
|
|
|
*/ |
97
|
|
|
public function setTables($tables) |
98
|
|
|
{ |
99
|
|
|
if (!empty($this->ignoreTables)) { |
100
|
|
|
throw new \Exception("You can choose only once between tables and ignoreTables at a time"); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if (is_string($tables)) { |
104
|
|
|
$tables = [$tables]; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
if (!is_array($tables)) { |
|
|
|
|
108
|
|
|
throw new \Exception("You can pass string or array"); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$this->tables = $tables; |
112
|
|
|
|
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
/** |
116
|
|
|
* @param string|array $tables |
117
|
|
|
* @throws \Exception |
118
|
|
|
*/ |
119
|
|
|
public function setIgnoreTables($tables) |
120
|
|
|
{ |
121
|
|
|
if (!empty($this->tables)) { |
122
|
|
|
throw new \Exception("You can choose only once between tables and ignoreTables at a time"); |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
if (is_string($tables)) { |
127
|
|
|
$tables = [$tables]; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
if (!is_array($tables)) { |
|
|
|
|
131
|
|
|
throw new \Exception("You can pass string or array"); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$this->ignoreTables = $tables; |
135
|
|
|
|
136
|
|
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
2 |
|
public function setCommandBinaryPath(string $path) |
140
|
|
|
{ |
141
|
2 |
|
$this->commandBinaryPath = $path; |
142
|
|
|
|
143
|
2 |
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function setDestinationPath(string $path) |
147
|
|
|
{ |
148
|
|
|
$this->destinationPath = $path; |
149
|
|
|
|
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function setRestorePath(string $path) |
154
|
|
|
{ |
155
|
|
|
$this->restorePath = $path; |
156
|
|
|
|
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
// Compress |
161
|
|
|
public function setCompressBinaryPath(string $path) |
162
|
|
|
{ |
163
|
|
|
$this->compressBinaryPath = $path; |
164
|
|
|
return $this; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function setCompressCommand(string $command) |
168
|
|
|
{ |
169
|
|
|
$this->compressCommand = $command; |
170
|
|
|
$this->isCompress = true; |
171
|
|
|
return $this; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function setCompressExtension(string $extension) |
175
|
|
|
{ |
176
|
|
|
$this->compressExtension = $extension; |
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
4 |
|
public function useCompress(string $command = "gzip", string $extension = ".gz", string $binary_path = "") |
181
|
|
|
{ |
182
|
4 |
|
$this->compressCommand = $command; |
183
|
4 |
|
$this->compressExtension = $extension; |
184
|
4 |
|
$this->compressBinaryPath = $binary_path; |
185
|
4 |
|
$this->isCompress = true; |
186
|
|
|
|
187
|
4 |
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
public function enableDebug() |
191
|
|
|
{ |
192
|
|
|
$this->debug = true; |
193
|
|
|
return $this; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function getDbName() |
197
|
|
|
{ |
198
|
|
|
return $this->dbName; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public function getUserName() |
202
|
|
|
{ |
203
|
|
|
return $this->username; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function getPassword() |
207
|
|
|
{ |
208
|
|
|
return $this->password; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
public function getHost() |
212
|
|
|
{ |
213
|
|
|
return $this->host; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function getPort() |
217
|
|
|
{ |
218
|
|
|
return $this->port; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
public function getSocket() |
222
|
|
|
{ |
223
|
|
|
return $this->port; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
public function getTimeOut() |
227
|
|
|
{ |
228
|
|
|
return $this->timeout; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
public function getCommandBinaryPath() |
232
|
|
|
{ |
233
|
|
|
return $this->commandBinaryPath; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
public function getDestinationPath() |
237
|
|
|
{ |
238
|
|
|
return $this->destinationPath; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
public function getRestorePath() |
242
|
|
|
{ |
243
|
|
|
return $this->restorePath; |
244
|
|
|
} |
245
|
|
|
|
246
|
16 |
|
public function getCommand() |
247
|
|
|
{ |
248
|
16 |
|
return $this->command; |
249
|
|
|
} |
250
|
|
|
|
251
|
16 |
|
public function getTempFile() |
252
|
|
|
{ |
253
|
16 |
|
return $this->tempFile; |
254
|
|
|
} |
255
|
|
|
|
256
|
16 |
|
public function removeExtraSpaces(string $str) |
257
|
|
|
{ |
258
|
16 |
|
return preg_replace('/\s+/', ' ', $str); |
259
|
|
|
} |
260
|
|
|
} |
261
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.