PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.4.1
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.4.1
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 6 years ago Redis.php 6 years ago
Disk.php
104 lines
1 <?php
2 namespace NitroPack\SDK\StorageDriver;
3
4 class Disk {
5 public function getOsPath($parts) {
6 return implode(DIRECTORY_SEPARATOR, $parts);
7 }
8
9 public function deleteFile($path) {
10 return @unlink($path);
11 }
12
13 public function createDir($dir) {
14 if (!is_dir($dir) && !mkdir($dir, 0755, true)) {
15 return false;
16 }
17
18 return true;
19 }
20
21 public function deleteDir($dir) {
22 if (!is_dir($dir)) return true;
23 return $this->trunkDir($dir) && rmdir($dir);
24 }
25
26 public function trunkDir($dir) {
27 if (!is_dir($dir)) return true;
28 $dh = opendir($dir);
29 if ($dh === false) return false;
30
31 while (false !== ($entry = readdir($dh))) {
32 if ($entry == "." || $entry == "..") continue;
33 $path = $this->getOsPath(array($dir, $entry));
34 if (is_dir($path)) {
35 if (!$this->deleteDir($path)) {
36 closedir($dh);
37 return false;
38 }
39 } else {
40 if (!unlink($path)) {
41 closedir($dh);
42 return false;
43 }
44 }
45 }
46 closedir($dh);
47
48 return true;
49 }
50
51 public function isDirEmpty($dir) {
52 if (!is_dir($dir)) return false;
53 $dh = opendir($dir);
54 if ($dh === false) return false;
55
56 $isEmpty = true;
57 while (false !== ($entry = readdir($dh))) {
58 if ($entry == "." || $entry == "..") continue;
59 $isEmpty = false; // first entry which is not "." or ".." means the dir is not empty
60 break;
61 }
62 closedir($dh);
63
64 return $isEmpty;
65 }
66
67 public function dirForeach($dir, $callback) {
68 if (!is_dir($dir)) return false;
69 $dh = opendir($dir);
70 if ($dh === false) return false;
71
72 while (false !== ($entry = readdir($dh))) {
73 if ($entry == "." || $entry == "..") continue;
74 call_user_func($callback, $this->getOsPath(array($dir, $entry)));
75 }
76 closedir($dh);
77 return true;
78 }
79
80 public function mtime($filePath) {
81 return @filemtime($filePath);
82 }
83
84 public function touch($filePath) {
85 return @touch($filePath);
86 }
87
88 public function exists($filePath) {
89 return file_exists($filePath);
90 }
91
92 public function getContent($filePath) {
93 return file_get_contents($filePath);
94 }
95
96 public function setContent($file, $content) {
97 return @file_put_contents($file, $content);
98 }
99
100 public function rename($oldName, $newName) {
101 return @rename($oldName, $newName);
102 }
103 }
104