BackupEngineAbstract::getExportCommand()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Cornford\Backup\Engines;
4
5
use Cornford\Backup\Contracts\BackupEngineInterface;
6
use Cornford\Backup\BackupProcess;
7
8
abstract class BackupEngineAbstract implements BackupEngineInterface
9
{
10
    /**
11
     * Command instance.
12
     *
13
     * @var \Cornford\Backup\BackupProcess
14
     */
15
    protected static $backupProcessInstance;
16
17
    /**
18
     * Database export command.
19
     *
20
     * @var string
21
     */
22
    protected $exportCommand;
23
24
    /**
25
     * Database restore command.
26
     *
27
     * @var string
28
     */
29
    protected $restoreCommand;
30
31
    /**
32
     * Database name.
33
     *
34
     * @var string
35
     */
36
    protected $database;
37
38
    /**
39
     * Database hostname.
40
     *
41
     * @var string
42
     */
43
    protected $hostname;
44
45
    /**
46
     * Database port.
47
     *
48
     * @var string
49
     */
50
    protected $port;
51
52
    /**
53
     * Database username.
54
     *
55
     * @var string
56
     */
57
    protected $username;
58
59
    /**
60
     * Database password.
61
     *
62
     * @var string
63
     */
64
    protected $password;
65
66
    /**
67
     * Database options.
68
     *
69
     * @var array
70
     */
71
    protected $options;
72
73
    /**
74
     * Backup engine constructor.
75
     *
76
     * @param BackupProcess $backupProcess
77
     * @param string        $hostname
78
     * @param string        $port
79
     * @param string        $database
80
     * @param string        $username
81
     * @param string        $password
82
     * @param array         $options
83
     */
84
    public function __construct(
85
        BackupProcess $backupProcess,
86
        $database,
87
        $hostname = null,
88
        $port = null,
89
        $username = null,
90
        $password = null,
91
        array $options = []
92
    ) {
93
        $this->setBackupProcess($backupProcess);
94
        $this->setDatabase($database);
95
        $this->setHostname($hostname);
96
        $this->setPort($port);
97
        $this->setUsername($username);
98
        $this->setPassword($password);
99
        $this->setOptions($options);
100
    }
101
102
    /**
103
     * Set backup process instance.
104
     *
105
     * @param BackupProcess $value
106
     *
107
     * @return void
108
     */
109
    public function setBackupProcess(BackupProcess $value)
110
    {
111
        self::$backupProcessInstance = $value;
112
    }
113
114
    /**
115
     * Get backup process instance.
116
     *
117
     * @return BackupProcess
118
     */
119
    public function getBackupProcess()
120
    {
121
        return self::$backupProcessInstance;
122
    }
123
124
    /**
125
     * Set database export command.
126
     *
127
     * @param string $value
128
     *
129
     * @return self
130
     */
131
    public function setExportCommand($value)
132
    {
133
        $this->exportCommand = $value;
134
135
        return $this;
136
    }
137
138
    /**
139
     * Get database export command.
140
     *
141
     * @return string
142
     */
143
    public function getExportCommand()
144
    {
145
        return $this->exportCommand;
146
    }
147
148
    /**
149
     * Set database restore command.
150
     *
151
     * @param string $value
152
     *
153
     * @return self
154
     */
155
    public function setRestoreCommand($value)
156
    {
157
        $this->restoreCommand = $value;
158
159
        return $this;
160
    }
161
162
    /**
163
     * Get database restore command.
164
     *
165
     * @return string
166
     */
167
    public function getRestoreCommand()
168
    {
169
        return $this->restoreCommand;
170
    }
171
172
    /**
173
     * Set database name.
174
     *
175
     * @param string $value
176
     *
177
     * @return self
178
     */
179
    public function setDatabase($value)
180
    {
181
        $this->database = $value;
182
183
        return $this;
184
    }
185
186
    /**
187
     * Get database name.
188
     *
189
     * @return string
190
     */
191
    public function getDatabase()
192
    {
193
        return $this->database;
194
    }
195
196
    /**
197
     * Set database hostname.
198
     *
199
     * @param string $value
200
     *
201
     * @return self
202
     */
203
    public function setHostname($value)
204
    {
205
        $this->hostname = $value;
206
207
        return $this;
208
    }
209
210
    /**
211
     * Get database hostname.
212
     *
213
     * @return string
214
     */
215
    public function getHostname()
216
    {
217
        return $this->hostname;
218
    }
219
220
    /**
221
     * Set database port.
222
     *
223
     * @param string $value
224
     *
225
     * @return self
226
     */
227
    public function setPort($value)
228
    {
229
        $this->port = $value;
230
231
        return $this;
232
    }
233
234
    /**
235
     * Get database port.
236
     *
237
     * @return string
238
     */
239
    public function getPort()
240
    {
241
        return $this->port;
242
    }
243
244
    /**
245
     * Set database username.
246
     *
247
     * @param string $value
248
     *
249
     * @return self
250
     */
251
    public function setUsername($value)
252
    {
253
        $this->username = $value;
254
255
        return $this;
256
    }
257
258
    /**
259
     * Get database username.
260
     *
261
     * @return string
262
     */
263
    public function getUsername()
264
    {
265
        return $this->username;
266
    }
267
268
    /**
269
     * Set database password.
270
     *
271
     * @param string $value
272
     *
273
     * @return self
274
     */
275
    public function setPassword($value)
276
    {
277
        $this->password = $value;
278
279
        return $this;
280
    }
281
282
    /**
283
     * Get database password.
284
     *
285
     * @return string
286
     */
287
    public function getPassword()
288
    {
289
        return $this->password;
290
    }
291
292
    /**
293
     * Set database options.
294
     *
295
     * @param array $value
296
     *
297
     * @return self
298
     */
299
    public function setOptions($value)
300
    {
301
        $this->options = $value;
302
303
        return $this;
304
    }
305
306
    /**
307
     * Get database options.
308
     *
309
     * @return array
310
     */
311
    public function getOptions()
312
    {
313
        return $this->options;
314
    }
315
316
    /**
317
     * Get export process.
318
     *
319
     * @return string
320
     */
321
    abstract public function getExportProcess();
322
323
    /**
324
     * Get restore process.
325
     *
326
     * @return string
327
     */
328
    abstract public function getRestoreProcess();
329
330
    /**
331
     * Get database file extension.
332
     *
333
     * @return string
334
     */
335
    abstract public function getFileExtension();
336
337
    /**
338
     * Export the database to a file.
339
     *
340
     * @param string $filepath
341
     *
342
     * @return bool
343
     */
344
    abstract public function export($filepath);
345
346
    /**
347
     * Restore the database from a file path.
348
     *
349
     * @param string $filepath
350
     *
351
     * @return bool
352
     */
353
    abstract public function restore($filepath);
354
355
    /**
356
     * Get the process output.
357
     *
358
     * @return string
359
     */
360
    public function getProcessOutput()
361
    {
362
        return self::$backupProcessInstance->getOutput();
363
    }
364
}
365