PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.5.2
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.5.2
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / nitropack-sdk / NitroPack / SDK / StorageDriver / Disk.php
nitropack / nitropack-sdk / NitroPack / SDK / StorageDriver Last commit date
Disk.php 5 years ago DiskFileHandle.php 5 years ago Redis.php 5 years ago RedisFileHandle.php 5 years ago
Disk.php
177 lines
1 <?php
2 namespace NitroPack\SDK\StorageDriver;
3
4 use \NitroPack\SDK\FileHandle;
5
6 class Disk {
7 public function getOsPath($parts) {
8 return implode(DIRECTORY_SEPARATOR, $parts);
9 }
10
11 public function deleteFile($path) {
12 return @unlink($path);
13 }
14
15 public function createDir($dir) {
16 if (!is_dir($dir) && !mkdir($dir, 0755, true)) {
17 return false;
18 }
19
20 return true;
21 }
22
23 public function deleteDir($dir) {
24 if (!is_dir($dir)) return true;
25 return $this->trunkDir($dir) && rmdir($dir);
26 }
27
28 public function trunkDir($dir) {
29 if (!is_dir($dir)) return true;
30 $dh = opendir($dir);
31 if ($dh === false) return false;
32
33 while (false !== ($entry = readdir($dh))) {
34 if ($entry == "." || $entry == "..") continue;
35 $path = $this->getOsPath(array($dir, $entry));
36 if (is_dir($path)) {
37 if (!$this->deleteDir($path)) {
38 closedir($dh);
39 return false;
40 }
41 } else {
42 if (!unlink($path)) {
43 closedir($dh);
44 return false;
45 }
46 }
47 }
48 closedir($dh);
49
50 return true;
51 }
52
53 public function isDirEmpty($dir) {
54 if (!is_dir($dir)) return false;
55 $dh = opendir($dir);
56 if ($dh === false) return false;
57
58 $isEmpty = true;
59 while (false !== ($entry = readdir($dh))) {
60 if ($entry == "." || $entry == "..") continue;
61 $isEmpty = false; // first entry which is not "." or ".." means the dir is not empty
62 break;
63 }
64 closedir($dh);
65
66 return $isEmpty;
67 }
68
69 public function dirForeach($dir, $callback) {
70 if (!is_dir($dir)) return false;
71 $dh = opendir($dir);
72 if ($dh === false) return false;
73
74 while (false !== ($entry = readdir($dh))) {
75 if ($entry == "." || $entry == "..") continue;
76 call_user_func($callback, $this->getOsPath(array($dir, $entry)));
77 }
78 closedir($dh);
79 return true;
80 }
81
82 public function mtime($filePath) {
83 return @filemtime($filePath);
84 }
85
86 public function touch($filePath) {
87 return @touch($filePath);
88 }
89
90 public function exists($filePath) {
91 return file_exists($filePath);
92 }
93
94 public function getContent($filePath) {
95 return file_get_contents($filePath);
96 }
97
98 public function setContent($file, $content) {
99 return @file_put_contents($file, $content);
100 }
101
102 public function rename($oldName, $newName) {
103 return @rename($oldName, $newName);
104 }
105
106 public function fopen($file, $mode) {
107 $fh = @fopen($file, $mode);
108 if ($fh) {
109 return new DiskFileHandle($fh);
110 } else {
111 return false;
112 }
113 }
114
115 public function fclose($fh) {
116 if (!($fh instanceof FileHandle)) return false;
117 return @fclose($fh->getHandle());
118 }
119
120 public function fflush($fh) {
121 if (!($fh instanceof FileHandle)) return false;
122 return @fflush($fh->getHandle());
123 }
124
125 public function fseek($fh, $offset, $whence = SEEK_SET) {
126 if (!($fh instanceof FileHandle)) return false;
127 return @fseek($fh->getHandle(), $offset, $whence);
128 }
129
130 public function ftell($fh) {
131 if (!($fh instanceof FileHandle)) return false;
132 return @ftell($fh->getHandle());
133 }
134
135 public function fwrite($fh, $string, $length = NULL) {
136 if (!($fh instanceof FileHandle)) return false;
137 if ($length !== NULL) {
138 return @fwrite($fh->getHandle(), $string, $length);
139 } else {
140 return @fwrite($fh->getHandle(), $string);
141 }
142 }
143
144 public function fread($fh, $length) {
145 if (!($fh instanceof FileHandle)) return false;
146 return @fread($fh->getHandle(), $length);
147 }
148
149 public function fgetc($fh) {
150 if (!($fh instanceof FileHandle)) return false;
151 return @fgetc($fh->getHandle());
152 }
153
154 public function fgets($fh, $length = NULL) {
155 if (!($fh instanceof FileHandle)) return false;
156 if ($length !== NULL) {
157 return @fgets($fh->getHandle(), $length);
158 } else {
159 return @fgets($fh->getHandle());
160 }
161 }
162
163 public function flock($fh, $operation, $wouldblock = NULL) {
164 if (!($fh instanceof FileHandle)) return false;
165 if ($wouldblock !== NULL) {
166 return @flock($fh->getHandle(), $operation, $wouldblock);
167 } else {
168 return @flock($fh->getHandle(), $operation);
169 }
170 }
171
172 public function feof($fh) {
173 if (!($fh instanceof FileHandle)) return false;
174 return @feof($fh->getHandle());
175 }
176 }
177