1
|
|
|
<?php |
2
|
|
|
namespace phpbu\App\Backup\Source; |
3
|
|
|
|
4
|
|
|
use phpbu\App\Exception; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Status class. |
8
|
|
|
* |
9
|
|
|
* @package phpbu |
10
|
|
|
* @subpackage Backup |
11
|
|
|
* @author Sebastian Feldmann <[email protected]> |
12
|
|
|
* @copyright Sebastian Feldmann <[email protected]> |
13
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
14
|
|
|
* @link http://phpbu.de/ |
15
|
|
|
* @since Class available since Release 2.0.1 |
16
|
|
|
*/ |
17
|
|
|
class Status |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Source handles compression by itself. |
21
|
|
|
* |
22
|
|
|
* @var boolean |
23
|
|
|
*/ |
24
|
|
|
private $handledCompression = true; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Is created backup a directory |
28
|
|
|
* |
29
|
|
|
* @var bool |
30
|
|
|
*/ |
31
|
|
|
private $dataPathIsDir = false; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Path to generated source data. |
35
|
|
|
* |
36
|
12 |
|
* @var string |
37
|
|
|
*/ |
38
|
12 |
|
private $dataPath; |
39
|
12 |
|
|
40
|
|
|
/** |
41
|
|
|
* Source does not handle compression. |
42
|
|
|
* |
43
|
|
|
* @param string $path |
44
|
|
|
* @return \phpbu\App\Backup\Source\Status |
45
|
|
|
*/ |
46
|
8 |
|
public function uncompressedFile($path) |
47
|
|
|
{ |
48
|
8 |
|
$this->handledCompression = false; |
49
|
8 |
|
$this->dataPath = $path; |
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param $path |
55
|
|
|
* @return \phpbu\App\Backup\Source\Status |
56
|
|
|
*/ |
57
|
9 |
|
public function uncompressedDirectory($path) |
58
|
|
|
{ |
59
|
9 |
|
$this->dataPathIsDir = true; |
60
|
|
|
return $this->uncompressedFile($path); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Did the Source handle the compression. |
65
|
|
|
* |
66
|
|
|
* @return boolean |
67
|
|
|
*/ |
68
|
8 |
|
public function handledCompression() |
69
|
|
|
{ |
70
|
8 |
|
return $this->handledCompression; |
71
|
8 |
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Is created backup data a directory. |
75
|
|
|
* |
76
|
|
|
* @return bool |
77
|
|
|
*/ |
78
|
|
|
public function isDirectory() |
79
|
|
|
{ |
80
|
3 |
|
return $this->dataPathIsDir; |
81
|
|
|
} |
82
|
3 |
|
|
83
|
1 |
|
/** |
84
|
|
|
* Return data location. |
85
|
2 |
|
* |
86
|
|
|
* @return string |
87
|
|
|
* @throws \phpbu\App\Exception |
88
|
|
|
*/ |
89
|
|
|
public function getDataPath() |
90
|
|
|
{ |
91
|
|
|
if ($this->handledCompression) { |
92
|
|
|
throw new Exception('source already handled compression'); |
93
|
12 |
|
} |
94
|
|
|
return $this->dataPath; |
95
|
12 |
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Static constructor for fluent interface calls. |
99
|
|
|
* |
100
|
|
|
* @return \phpbu\App\Backup\Source\Status |
101
|
|
|
*/ |
102
|
|
|
public static function create() |
103
|
|
|
{ |
104
|
|
|
return new self(); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|