|
1
|
|
|
<?php |
|
2
|
|
|
namespace phpbu\App\Backup; |
|
3
|
|
|
|
|
4
|
|
|
use phpbu\App\Util; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Collector class. |
|
8
|
|
|
* |
|
9
|
|
|
* @package phpbu |
|
10
|
|
|
* @subpackage Backup |
|
11
|
|
|
* @author Sebastian Feldmann <[email protected]> |
|
12
|
|
|
* @author Vitaly Baev <[email protected]> |
|
13
|
|
|
* @copyright Sebastian Feldmann <[email protected]> |
|
14
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
|
15
|
|
|
* @link http://phpbu.de/ |
|
16
|
|
|
* @since Class available since Release 5.1.0 |
|
17
|
|
|
*/ |
|
18
|
|
|
abstract class Collector |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Path class. |
|
22
|
|
|
* |
|
23
|
|
|
* @var Path |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $path; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Backup target |
|
29
|
|
|
* |
|
30
|
|
|
* @var \phpbu\App\Backup\Target |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $target; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Target filename regex |
|
36
|
|
|
* |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $fileRegex; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Collection cache |
|
43
|
|
|
* |
|
44
|
|
|
* @var \phpbu\App\Backup\File[] |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $files; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Setting up |
|
50
|
|
|
* |
|
51
|
|
|
* @param \phpbu\App\Backup\Target $target |
|
52
|
|
|
*/ |
|
53
|
4 |
|
public function setUp(Target $target) |
|
54
|
|
|
{ |
|
55
|
4 |
|
$this->target = $target; |
|
56
|
4 |
|
$this->fileRegex = Util\Path::datePlaceholdersToRegex($target->getFilenameRaw()); |
|
57
|
4 |
|
$this->files = []; |
|
58
|
4 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Return true if target full path matches file and path regex. |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $targetPath Full path to the remote file to check |
|
64
|
|
|
* @return bool |
|
65
|
|
|
*/ |
|
66
|
1 |
|
protected function isFileMatch(string $targetPath): bool |
|
67
|
|
|
{ |
|
68
|
1 |
|
$rawPath = Util\Path::withoutLeadingSlash($this->path->getPathRaw()); |
|
69
|
1 |
|
$pathRegex = Util\Path::datePlaceholdersToRegex($rawPath); |
|
70
|
1 |
|
$pathRegex .= $pathRegex ? '/' : ''; |
|
71
|
1 |
|
$fileRegex = Util\Path::datePlaceholdersToRegex($this->target->getFilenameRaw()); |
|
72
|
1 |
|
return preg_match('#' . $pathRegex . $fileRegex . '$#i', $targetPath); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Returns true if filename matches the target regex |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $filename |
|
79
|
|
|
* @return bool |
|
80
|
|
|
*/ |
|
81
|
13 |
|
protected function isFilenameMatch(string $filename): bool |
|
82
|
|
|
{ |
|
83
|
13 |
|
return preg_match('#' . $this->fileRegex . '#i', $filename); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return Path |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getPath(): Path |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->path; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Get all created backups. |
|
96
|
|
|
* |
|
97
|
|
|
* @return \phpbu\App\Backup\File[] |
|
98
|
|
|
*/ |
|
99
|
|
|
abstract public function getBackupFiles() : array; |
|
100
|
|
|
} |
|
101
|
|
|
|