1 | <?php |
||
22 | class PermissionHelper |
||
23 | { |
||
24 | const MODE_USER_READ = 0400; |
||
25 | const MODE_USER_WRITE = 0200; |
||
26 | |||
27 | const MODE_GROUP_READ = 0040; |
||
28 | const MODE_GROUP_WRITE = 0020; |
||
29 | |||
30 | const MODE_WORLD_READ = 0004; |
||
31 | const MODE_WORLD_WRITE = 0002; |
||
32 | |||
33 | /** |
||
34 | * @var Node |
||
35 | */ |
||
36 | protected $node; |
||
37 | |||
38 | protected $userid; |
||
39 | protected $groupid; |
||
40 | |||
41 | /** |
||
42 | * @param integer|null $uid |
||
43 | * @param integer|null $gid |
||
44 | */ |
||
45 | public function __construct($uid = null, $gid = null) |
||
50 | |||
51 | /** |
||
52 | * Checks whether user_id on file is the same as executing user |
||
53 | * |
||
54 | * @return bool |
||
55 | */ |
||
56 | public function userIsOwner() |
||
60 | |||
61 | /** |
||
62 | * Checks whether file is readable for user |
||
63 | * |
||
64 | * @return bool |
||
65 | */ |
||
66 | public function userCanRead() |
||
70 | |||
71 | /** |
||
72 | * Checks whether file is writable for user |
||
73 | * |
||
74 | * @return bool |
||
75 | */ |
||
76 | public function userCanWrite() |
||
80 | |||
81 | /** |
||
82 | * Checks whether group_id on file is the same as executing user |
||
83 | * |
||
84 | * @return bool |
||
85 | */ |
||
86 | public function groupIsOwner() |
||
90 | |||
91 | /** |
||
92 | * Checks whether file is readable for group |
||
93 | * |
||
94 | * @return bool |
||
95 | */ |
||
96 | public function groupCanRead() |
||
100 | |||
101 | /** |
||
102 | * Checks whether file is writable for group |
||
103 | * |
||
104 | * @return bool |
||
105 | */ |
||
106 | public function groupCanWrite() |
||
110 | |||
111 | /** |
||
112 | * Checks whether file is readable for world |
||
113 | * |
||
114 | * @return bool |
||
115 | */ |
||
116 | public function worldCanRead() |
||
120 | |||
121 | /** |
||
122 | * Checks whether file is writable for world |
||
123 | * |
||
124 | * @return bool |
||
125 | */ |
||
126 | public function worldCanWrite() |
||
130 | |||
131 | /** |
||
132 | * Checks whether file is readable (by user, group or world) |
||
133 | * |
||
134 | * @return bool |
||
135 | */ |
||
136 | public function isReadable() |
||
140 | |||
141 | /** |
||
142 | * Checks whether file is writable (by user, group or world) |
||
143 | * |
||
144 | * @return bool |
||
145 | */ |
||
146 | public function isWritable() |
||
150 | |||
151 | /** |
||
152 | * Checks whether userid is 0 - root. |
||
153 | * |
||
154 | * @return bool |
||
155 | */ |
||
156 | public function userIsRoot() |
||
160 | |||
161 | /** |
||
162 | * @param \VirtualFileSystem\Structure\Node $node |
||
163 | * |
||
164 | * @return PermissionHelper |
||
165 | */ |
||
166 | public function setNode($node) |
||
172 | } |
||
173 |