|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kint\Object\Representation; |
|
4
|
|
|
|
|
5
|
|
|
use SplFileInfo; |
|
6
|
|
|
|
|
7
|
|
|
class SplFileInfoRepresentation extends Representation |
|
8
|
|
|
{ |
|
9
|
|
|
public $perms = null; |
|
10
|
|
|
public $flags = null; |
|
11
|
|
|
public $path = null; |
|
12
|
|
|
public $realpath = null; |
|
13
|
|
|
public $linktarget = null; |
|
14
|
|
|
public $size = null; |
|
15
|
|
|
public $is_dir = false; |
|
|
|
|
|
|
16
|
|
|
public $is_file = false; |
|
|
|
|
|
|
17
|
|
|
public $is_link = false; |
|
|
|
|
|
|
18
|
|
|
public $owner = null; |
|
19
|
|
|
public $group = null; |
|
20
|
|
|
public $ctime = null; |
|
21
|
|
|
public $mtime = null; |
|
22
|
|
|
public $typename = 'Unknown file'; |
|
23
|
|
|
public $typeflag = '-'; |
|
24
|
|
|
public $hints = array('fspath'); |
|
25
|
|
|
|
|
26
|
|
|
public function __construct(SplFileInfo $fileInfo) |
|
27
|
|
|
{ |
|
28
|
|
|
if (!file_exists($fileInfo->getPathname())) { |
|
29
|
|
|
return; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
$this->perms = $fileInfo->getPerms(); |
|
33
|
|
|
$this->size = $fileInfo->getSize(); |
|
34
|
|
|
$this->is_dir = $fileInfo->isDir(); |
|
35
|
|
|
$this->is_file = $fileInfo->isFile(); |
|
36
|
|
|
$this->is_link = $fileInfo->isLink(); |
|
37
|
|
|
$this->owner = $fileInfo->getOwner(); |
|
38
|
|
|
$this->group = $fileInfo->getGroup(); |
|
39
|
|
|
$this->ctime = $fileInfo->getCTime(); |
|
40
|
|
|
$this->mtime = $fileInfo->getMTime(); |
|
41
|
|
|
|
|
42
|
|
|
if (($this->perms & 0xC000) === 0xC000) { |
|
43
|
|
|
$this->typename = 'File socket'; |
|
44
|
|
|
$this->typeflag = 's'; |
|
45
|
|
|
} elseif ($this->is_file) { |
|
46
|
|
|
if ($this->is_link) { |
|
47
|
|
|
$this->typename = 'File symlink'; |
|
48
|
|
|
$this->typeflag = 'l'; |
|
49
|
|
|
} else { |
|
50
|
|
|
$this->typename = 'File'; |
|
51
|
|
|
$this->typeflag = '-'; |
|
52
|
|
|
} |
|
53
|
|
|
} elseif (($this->perms & 0x6000) === 0x6000) { |
|
54
|
|
|
$this->typename = 'Block special file'; |
|
55
|
|
|
$this->typeflag = 'b'; |
|
56
|
|
|
} elseif ($this->is_dir) { |
|
57
|
|
|
if ($this->is_link) { |
|
58
|
|
|
$this->typename = 'Directory symlink'; |
|
59
|
|
|
$this->typeflag = 'l'; |
|
60
|
|
|
} else { |
|
61
|
|
|
$this->typename = 'Directory'; |
|
62
|
|
|
$this->typeflag = 'd'; |
|
63
|
|
|
} |
|
64
|
|
|
} elseif (($this->perms & 0x2000) === 0x2000) { |
|
65
|
|
|
$this->typename = 'Character special file'; |
|
66
|
|
|
$this->typeflag = 'c'; |
|
67
|
|
|
} elseif (($this->perms & 0x1000) === 0x1000) { |
|
68
|
|
|
$this->typename = 'FIFO pipe file'; |
|
69
|
|
|
$this->typeflag = 'p'; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
parent::__construct('SplFileInfo'); |
|
73
|
|
|
|
|
74
|
|
|
$this->path = $fileInfo->getPathname(); |
|
75
|
|
|
$this->realpath = realpath($this->path); |
|
76
|
|
|
|
|
77
|
|
|
if ($this->is_link && method_exists($fileInfo, 'getLinktarget')) { |
|
78
|
|
|
$this->linktarget = $fileInfo->getLinkTarget(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$this->flags = array($this->typeflag); |
|
82
|
|
|
|
|
83
|
|
|
// User |
|
84
|
|
|
$this->flags[] = (($this->perms & 0400) ? 'r' : '-'); |
|
85
|
|
|
$this->flags[] = (($this->perms & 0200) ? 'w' : '-'); |
|
86
|
|
View Code Duplication |
if ($this->perms & 0100) { |
|
|
|
|
|
|
87
|
|
|
$this->flags[] = ($this->perms & 04000) ? 's' : 'x'; |
|
88
|
|
|
} else { |
|
89
|
|
|
$this->flags[] = ($this->perms & 04000) ? 'S' : '-'; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
// Group |
|
93
|
|
|
$this->flags[] = (($this->perms & 0040) ? 'r' : '-'); |
|
94
|
|
|
$this->flags[] = (($this->perms & 0020) ? 'w' : '-'); |
|
95
|
|
View Code Duplication |
if ($this->perms & 0010) { |
|
|
|
|
|
|
96
|
|
|
$this->flags[] = ($this->perms & 02000) ? 's' : 'x'; |
|
97
|
|
|
} else { |
|
98
|
|
|
$this->flags[] = ($this->perms & 02000) ? 'S' : '-'; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
// Other |
|
102
|
|
|
$this->flags[] = (($this->perms & 0004) ? 'r' : '-'); |
|
103
|
|
|
$this->flags[] = (($this->perms & 0002) ? 'w' : '-'); |
|
104
|
|
View Code Duplication |
if ($this->perms & 0001) { |
|
|
|
|
|
|
105
|
|
|
$this->flags[] = ($this->perms & 01000) ? 's' : 'x'; |
|
106
|
|
|
} else { |
|
107
|
|
|
$this->flags[] = ($this->perms & 01000) ? 'S' : '-'; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
$this->contents = implode($this->flags).' '.$this->owner.' '.$this->group; |
|
|
|
|
|
|
111
|
|
|
$this->contents .= ' '.$this->getSize().' '.$this->getMTime().' '; |
|
112
|
|
|
|
|
113
|
|
|
if ($this->is_link && $this->linktarget) { |
|
114
|
|
|
$this->contents .= $this->path.' -> '.$this->linktarget; |
|
115
|
|
|
} elseif (strlen($this->realpath) < strlen($this->path)) { |
|
116
|
|
|
$this->contents .= $this->realpath; |
|
117
|
|
|
} else { |
|
118
|
|
|
$this->contents .= $this->path; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function getLabel() |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->typename.' ('.$this->getSize().')'; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function getSize() |
|
128
|
|
|
{ |
|
129
|
|
|
static $unit = array('B', 'KB', 'MB', 'GB', 'TB'); |
|
130
|
|
|
|
|
131
|
|
|
$size = $this->size; |
|
132
|
|
|
|
|
133
|
|
|
if ($this->size) { |
|
134
|
|
|
$i = floor(log($this->size, 1024)); |
|
135
|
|
|
$size = round($this->size / pow(1024, $i), 2).$unit[$i]; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
return $size; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function getMTime() |
|
142
|
|
|
{ |
|
143
|
|
|
$year = date('Y', $this->mtime); |
|
144
|
|
|
|
|
145
|
|
|
if ($year !== date('Y')) { |
|
146
|
|
|
return date('M d Y', $this->mtime); |
|
147
|
|
|
} else { |
|
148
|
|
|
return date('M d H:i', $this->mtime); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.