PluginProbe
JetBackup – Backup, Restore & Migrate / 3.1.21.3
JetBackup – Backup, Restore & Migrate v3.1.21.3
3.1.23.6 3.1.23.5 3.1.23.3 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 All 82 releases
backup / src / JetBackup / Filesystem / File.php
File.php
67 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }