Total Complexity | 15 |
Total Lines | 86 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
9 | class FileHelper |
||
10 | { |
||
11 | /** |
||
12 | * 判断文件是否存在 |
||
13 | * |
||
14 | * @return boolean |
||
15 | */ |
||
16 | public static function exist(string $path):bool |
||
17 | { |
||
18 | return Path::format($path) !== null; |
||
19 | } |
||
20 | |||
21 | /** |
||
22 | * 删除文件 |
||
23 | * |
||
24 | * @return boolean |
||
25 | */ |
||
26 | public static function delete(string $filename):bool |
||
27 | { |
||
28 | if (($path=Path::format($filename)) !== null) { |
||
29 | if (!is_writable($path)) { |
||
30 | return false; |
||
31 | } |
||
32 | return unlink($path); |
||
33 | } |
||
34 | return true; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * 移动文件 |
||
39 | * |
||
40 | * @param string $src |
||
41 | * @param string $dest |
||
42 | * @return boolean |
||
43 | */ |
||
44 | public static function move(string $src, string $dest):bool |
||
45 | { |
||
46 | if (($path=Path::format($src)) !== null && is_writable(dirname($dest))) { |
||
47 | return rename($path, $dest); |
||
48 | } |
||
49 | return false; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * 复制文件 |
||
54 | * |
||
55 | * @param string $src |
||
56 | * @param string $dest |
||
57 | * @return boolean |
||
58 | */ |
||
59 | public static function copy(string $src, string $dest):bool |
||
60 | { |
||
61 | if (($path=Path::format($src)) !== null && is_writable(dirname($dest))) { |
||
62 | return copy($path, $dest); |
||
63 | } |
||
64 | return false; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * 写入文件 |
||
69 | * |
||
70 | * @param string $filename |
||
71 | * @param string $content |
||
72 | * @param integer $flags |
||
73 | * @return boolean |
||
74 | */ |
||
75 | public static function put(string $filename, string $content, int $flags = 0):bool |
||
76 | { |
||
77 | if (is_writeable(dirname($filename))) { |
||
78 | return file_put_contents($filename, $content, $flags) > 0; |
||
79 | } |
||
80 | return false; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * 读取文件 |
||
85 | * |
||
86 | * @param string $name |
||
87 | * @return string|null |
||
88 | */ |
||
89 | public static function get(string $filename):?string |
||
95 | } |
||
96 | } |
||
97 |