1 | <?php |
||
18 | abstract class Collector |
||
19 | { |
||
20 | /** |
||
21 | * Backup target |
||
22 | * |
||
23 | * @var \phpbu\App\Backup\Target |
||
24 | */ |
||
25 | protected $target; |
||
26 | |||
27 | /** |
||
28 | * Target filename regex |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $fileRegex; |
||
33 | |||
34 | /** |
||
35 | * Collection cache |
||
36 | * |
||
37 | * @var \phpbu\App\Backup\File[] |
||
38 | */ |
||
39 | protected $files; |
||
40 | |||
41 | /** |
||
42 | * Setting up |
||
43 | * |
||
44 | * @param \phpbu\App\Backup\Target $target |
||
45 | */ |
||
46 | 4 | public function setUp(Target $target) |
|
47 | { |
||
48 | 4 | $this->target = $target; |
|
49 | 4 | $this->fileRegex = Str::datePlaceholdersToRegex($target->getFilenameRaw()); |
|
50 | 4 | $this->files = []; |
|
51 | 4 | } |
|
52 | |||
53 | /** |
||
54 | * Returns true if filename matches the target regex |
||
55 | * |
||
56 | * @param string $filename |
||
57 | * @return bool |
||
58 | */ |
||
59 | 13 | protected function isFilenameMatch(string $filename): bool |
|
60 | { |
||
61 | 13 | return preg_match('#'.$this->fileRegex . '#i', $filename); |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * Get all created backups. |
||
66 | * |
||
67 | * @return \phpbu\App\Backup\File[] |
||
68 | */ |
||
69 | abstract public function getBackupFiles() : array; |
||
70 | } |
||
71 |