PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.11.1
JetBackup – Backup, Restore & Migrate v3.1.11.1
3.1.22.4 3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / Filesystem / File.php
backup / src / JetBackup / Filesystem Last commit date
.htaccess 11 months ago File.php 11 months ago index.html 11 months ago web.config 11 months ago
File.php
67 lines
1 <?php
2
3 namespace JetBackup\Filesystem;
4
5 use JetBackup\Exception\IOException;
6
7 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
8
9 class File {
10
11 const IFMT = 0170000;
12 const IFDIR = 0040000;
13 const IFCHR = 0020000;
14 const IFBLK = 0060000;
15 const IFREG = 0100000;
16 const IFIFO = 0010000;
17 const IFLNK = 0120000;
18 const IFSOCK = 0140000;
19
20 private $_file;
21 private $_stat;
22 private $_readable;
23 private $_fixed_size;
24
25 public function __construct($file) {
26 $this->_file = $file;
27 }
28
29 /**
30 * @throws IOException
31 */
32 public function getStat($key = null, $default = null) {
33 if ($this->_stat === null) {
34 $this->_stat = @lstat($this->_file);
35 if (!$this->_stat) throw new IOException('[getStat] Unable to retrieve file status: ' . $this->_file);
36 }
37 return $key ? ($this->_stat[$key] ?? $default) : $this->_stat;
38 }
39
40 public function path():string { return $this->_file; }
41 public function dir() { return $this->isDir() ? dir($this->path()) : null; }
42 public function exists():bool { return $this->_stat !== null || file_exists($this->_file); }
43 public function size():int {
44 if($this->_fixed_size === null) {
45 if($this->isDir() || $this->isLink() || strpos($this->_file, "\0") !== false) $this->_fixed_size = true;
46 else $this->_fixed_size = false;
47 }
48 if($this->_fixed_size) return 0;
49 return (int) $this->getStat('size', 0);
50 }
51 public function mtime():int { return (int) $this->getStat('mtime', 0); }
52 public function uid():int { return (int) $this->getStat('uid', 0); }
53 public function gid():int { return (int) $this->getStat('gid', 0); }
54 public function mode():int { return (int) $this->getStat('mode', 0); }
55
56 public function isDir():bool { return ($this->mode() & self::IFMT) == self::IFDIR; }
57 public function isFile():bool { return ($this->mode() & self::IFMT) == self::IFREG; }
58 public function isLink():bool { return ($this->mode() & self::IFMT) == self::IFLNK; }
59 public function isBlockDevice():bool { return ($this->mode() & self::IFMT) == self::IFBLK; }
60 public function isCharacterDevice():bool { return ($this->mode() & self::IFMT) == self::IFCHR; }
61 public function isFifo():bool { return ($this->mode() & self::IFMT) == self::IFIFO; }
62 public function isSocket():bool { return ($this->mode() & self::IFMT) == self::IFSOCK; }
63 public function isReadable():bool {
64 if($this->_readable === null) $this->_readable = is_readable($this->_file);
65 return $this->_readable;
66 }
67 }