FileAttribUtil.php
2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace PhpZip\Util;
use PhpZip\Constants\DosAttrs;
use PhpZip\Constants\UnixStat;
/**
* Class FileAttribUtil.
*
* @internal
*/
class FileAttribUtil implements DosAttrs, UnixStat
{
/**
* Get DOS mode,.
*
* @param int $xattr
*
* @return string
*/
public static function getDosMode($xattr)
{
$xattr = (int) $xattr;
$mode = (($xattr & self::DOS_DIRECTORY) === self::DOS_DIRECTORY) ? 'd' : '-';
$mode .= (($xattr & self::DOS_ARCHIVE) === self::DOS_ARCHIVE) ? 'a' : '-';
$mode .= (($xattr & self::DOS_READ_ONLY) === self::DOS_READ_ONLY) ? 'r' : '-';
$mode .= (($xattr & self::DOS_HIDDEN) === self::DOS_HIDDEN) ? 'h' : '-';
$mode .= (($xattr & self::DOS_SYSTEM) === self::DOS_SYSTEM) ? 's' : '-';
$mode .= (($xattr & self::DOS_LABEL) === self::DOS_LABEL) ? 'l' : '-';
return $mode;
}
/**
* @param int $permission
*
* @return string
*/
public static function getUnixMode($permission)
{
$mode = '';
$permission = (int) $permission;
switch ($permission & self::UNX_IFMT) {
case self::UNX_IFDIR:
$mode .= 'd';
break;
case self::UNX_IFREG:
$mode .= '-';
break;
case self::UNX_IFLNK:
$mode .= 'l';
break;
case self::UNX_IFBLK:
$mode .= 'b';
break;
case self::UNX_IFCHR:
$mode .= 'c';
break;
case self::UNX_IFIFO:
$mode .= 'p';
break;
case self::UNX_IFSOCK:
$mode .= 's';
break;
default:
$mode .= '?';
break;
}
$mode .= ($permission & self::UNX_IRUSR) ? 'r' : '-';
$mode .= ($permission & self::UNX_IWUSR) ? 'w' : '-';
if ($permission & self::UNX_IXUSR) {
$mode .= ($permission & self::UNX_ISUID) ? 's' : 'x';
} else {
$mode .= ($permission & self::UNX_ISUID) ? 'S' : '-'; // S==undefined
}
$mode .= ($permission & self::UNX_IRGRP) ? 'r' : '-';
$mode .= ($permission & self::UNX_IWGRP) ? 'w' : '-';
if ($permission & self::UNX_IXGRP) {
$mode .= ($permission & self::UNX_ISGID) ? 's' : 'x';
} // == self::UNX_ENFMT
else {
$mode .= ($permission & self::UNX_ISGID) ? 'S' : '-';
} // SunOS 4.1.x
$mode .= ($permission & self::UNX_IROTH) ? 'r' : '-';
$mode .= ($permission & self::UNX_IWOTH) ? 'w' : '-';
if ($permission & self::UNX_IXOTH) {
$mode .= ($permission & self::UNX_ISVTX) ? 't' : 'x';
} // "sticky bit"
else {
$mode .= ($permission & self::UNX_ISVTX) ? 'T' : '-';
} // T==undefined
return $mode;
}
}