|
1
|
|
|
<?php |
|
2
|
|
|
namespace phpbu\App\Backup\File; |
|
3
|
|
|
|
|
4
|
|
|
use phpbu\App\Backup\File; |
|
5
|
|
|
use SplFileInfo; |
|
6
|
|
|
use phpbu\App\Exception; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* File |
|
10
|
|
|
* |
|
11
|
|
|
* @package phpbu |
|
12
|
|
|
* @subpackage Backup |
|
13
|
|
|
* @author Sebastian Feldmann <[email protected]> |
|
14
|
|
|
* @copyright Sebastian Feldmann <[email protected]> |
|
15
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
|
16
|
|
|
* @link http://phpbu.de/ |
|
17
|
|
|
* @since Class available since Release 1.0.0 |
|
18
|
|
|
*/ |
|
19
|
|
|
class Local implements File |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* FileInfo |
|
23
|
|
|
* |
|
24
|
|
|
* @var \SplFileInfo |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $fileInfo; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Constructor |
|
30
|
|
|
* |
|
31
|
|
|
* @param SplFileInfo $fileInfo |
|
32
|
|
|
*/ |
|
33
|
19 |
|
public function __construct(SplFileInfo $fileInfo) |
|
34
|
|
|
{ |
|
35
|
19 |
|
$this->fileInfo = $fileInfo; |
|
36
|
19 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* FileInfo getter. |
|
40
|
|
|
* |
|
41
|
|
|
* @return SplFileInfo |
|
42
|
|
|
*/ |
|
43
|
1 |
|
public function getFileInfo() |
|
44
|
|
|
{ |
|
45
|
1 |
|
return $this->fileInfo; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Return the filesize. |
|
50
|
|
|
* |
|
51
|
|
|
* @return integer |
|
52
|
|
|
*/ |
|
53
|
1 |
|
public function getSize(): int |
|
54
|
|
|
{ |
|
55
|
1 |
|
return $this->fileInfo->getSize(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Return the filename. |
|
60
|
|
|
* |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
1 |
|
public function getFilename(): string |
|
64
|
|
|
{ |
|
65
|
1 |
|
return $this->fileInfo->getFilename(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Return the full path and filename. |
|
70
|
|
|
* |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
2 |
|
public function getPathname(): string |
|
74
|
|
|
{ |
|
75
|
2 |
|
return $this->fileInfo->getPathname(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Return the path. |
|
80
|
|
|
* |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
1 |
|
public function getPath() |
|
84
|
|
|
{ |
|
85
|
1 |
|
return $this->fileInfo->getPath(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Return last modified date as unix timestamp. |
|
90
|
|
|
* |
|
91
|
|
|
* @return integer |
|
92
|
|
|
*/ |
|
93
|
1 |
|
public function getMTime(): int |
|
94
|
|
|
{ |
|
95
|
1 |
|
return $this->fileInfo->getMTime(); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Return whether the file is writable or not. |
|
100
|
|
|
* |
|
101
|
|
|
* @return boolean |
|
102
|
|
|
*/ |
|
103
|
1 |
|
public function isWritable(): bool |
|
104
|
|
|
{ |
|
105
|
1 |
|
return $this->fileInfo->isWritable(); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Deletes the file. |
|
110
|
|
|
* |
|
111
|
|
|
* @throws \phpbu\App\Exception |
|
112
|
|
|
*/ |
|
113
|
2 |
|
public function unlink() |
|
114
|
|
|
{ |
|
115
|
2 |
|
$old = error_reporting(0); |
|
116
|
2 |
|
if (!unlink($this->fileInfo->getPathname())) { |
|
117
|
1 |
|
error_reporting($old); |
|
118
|
1 |
|
throw new Exception(sprintf('can\'t delete file: %s', $this->fileInfo->getPathname())); |
|
119
|
|
|
} |
|
120
|
1 |
|
error_reporting($old); |
|
121
|
1 |
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|