1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PrettyBx\Support\Filesystem; |
6
|
|
|
|
7
|
|
|
use Illuminate\Support\Traits\Macroable; |
8
|
|
|
|
9
|
|
|
class Manager |
10
|
|
|
{ |
11
|
|
|
use Macroable; |
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* file_get_contents wrapper |
15
|
|
|
* |
16
|
|
|
* @access public |
17
|
|
|
* @param string $filename |
18
|
|
|
* @return mixed |
19
|
|
|
*/ |
20
|
|
|
public function getContents(string $filename) |
21
|
|
|
{ |
22
|
|
|
return file_get_contents($filename); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* file_put_contents wrapper |
27
|
|
|
* |
28
|
|
|
* @access public |
29
|
|
|
* @param string $filename |
30
|
|
|
* @param mixed $data |
31
|
|
|
* @return mixed |
32
|
|
|
*/ |
33
|
|
|
public function putContents(string $filename, $data) |
34
|
|
|
{ |
35
|
|
|
return file_put_contents($filename, $data); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Returns true if file exists |
40
|
|
|
* |
41
|
|
|
* @access public |
42
|
|
|
* @param string $filename |
43
|
|
|
* @return bool |
44
|
|
|
*/ |
45
|
|
|
public function exists(string $filename): bool |
46
|
|
|
{ |
47
|
|
|
return file_exists($filename); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* mkdir wrapper |
52
|
|
|
* |
53
|
|
|
* @access public |
54
|
|
|
* @param string $pathname |
55
|
|
|
* @param integer $mode Default: 0777 |
56
|
|
|
* @param boolean $recursive Default: false |
57
|
|
|
* @return bool |
58
|
|
|
*/ |
59
|
|
|
public function mkdir(string $pathname, int $mode = 0777, bool $recursive = false): bool |
60
|
|
|
{ |
61
|
|
|
return mkdir($pathname, $mode, $recursive); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* rename wrapper |
66
|
|
|
* |
67
|
|
|
* @access public |
68
|
|
|
* @param string $oldname |
69
|
|
|
* @param string $newname |
70
|
|
|
* @param resource $context |
71
|
|
|
* @return bool |
72
|
|
|
*/ |
73
|
|
|
public function rename(string $oldname, string $newname, resource $context = null): bool |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
return rename($oldname, $newname, $context); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* touch wrapper |
80
|
|
|
* |
81
|
|
|
* @access public |
82
|
|
|
* @param string $filename |
83
|
|
|
* @param int $time Default: null |
84
|
|
|
* @param int $atime Default: null |
85
|
|
|
* @return bool |
86
|
|
|
*/ |
87
|
|
|
public function touch(string $filename, int $time = null, int $atime = null): bool |
88
|
|
|
{ |
89
|
|
|
if (empty($time)) { |
90
|
|
|
$time = time(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
if (empty($atime)) { |
94
|
|
|
$atime = time(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return touch($filename, $time, $atime); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* getTempDir. |
102
|
|
|
* |
103
|
|
|
* @access public |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
public function getTempDir(): string |
107
|
|
|
{ |
108
|
|
|
return sys_get_temp_dir(); |
109
|
|
|
} |
110
|
|
|
} |