1
+ <?php
2
+
3
+ namespace Aternos \IO \System \Util ;
4
+
5
+ use Aternos \IO \Interfaces \Util \PermissionsClassInterface ;
6
+ use Aternos \IO \Interfaces \Util \PermissionsInterface ;
7
+
8
+ /**
9
+ * Class Permissions
10
+ *
11
+ * Holds permission classes for an element
12
+ *
13
+ * @package Aternos\IO\System\Util
14
+ */
15
+ class Permissions implements PermissionsInterface
16
+ {
17
+ /**
18
+ * @param int $permissions
19
+ * @return static
20
+ */
21
+ public static function fromNumeric (int $ permissions ): static
22
+ {
23
+ return new static (
24
+ new PermissionsClass (
25
+ ($ permissions & 0o100 ) === 0o100 ,
26
+ ($ permissions & 0o200 ) === 0o200 ,
27
+ ($ permissions & 0o400 ) === 0o400
28
+ ),
29
+ new PermissionsClass (
30
+ ($ permissions & 0o010 ) === 0o010 ,
31
+ ($ permissions & 0o020 ) === 0o020 ,
32
+ ($ permissions & 0o040 ) === 0o040
33
+ ),
34
+ new PermissionsClass (
35
+ ($ permissions & 0o001 ) === 0o001 ,
36
+ ($ permissions & 0o002 ) === 0o002 ,
37
+ ($ permissions & 0o004 ) === 0o004
38
+ )
39
+ );
40
+ }
41
+
42
+
43
+ /**
44
+ * @param PermissionsClassInterface $user
45
+ * @param PermissionsClassInterface $group
46
+ * @param PermissionsClassInterface $other
47
+ */
48
+ public function __construct (
49
+ protected PermissionsClassInterface $ user = new PermissionsClass (),
50
+ protected PermissionsClassInterface $ group = new PermissionsClass (),
51
+ protected PermissionsClassInterface $ other = new PermissionsClass ()
52
+ )
53
+ {
54
+ }
55
+
56
+ /**
57
+ * @inheritDoc
58
+ */
59
+ public function getUser (): PermissionsClassInterface
60
+ {
61
+ return $ this ->user ;
62
+ }
63
+
64
+ /**
65
+ * @inheritDoc
66
+ */
67
+ public function getGroup (): PermissionsClassInterface
68
+ {
69
+ return $ this ->group ;
70
+ }
71
+
72
+ /**
73
+ * @inheritDoc
74
+ */
75
+ public function getOther (): PermissionsClassInterface
76
+ {
77
+ return $ this ->other ;
78
+ }
79
+
80
+ /**
81
+ * @inheritDoc
82
+ */
83
+ public function setUser (PermissionsClassInterface $ user ): static
84
+ {
85
+ $ this ->user = $ user ;
86
+ return $ this ;
87
+ }
88
+
89
+ /**
90
+ * @inheritDoc
91
+ */
92
+ public function setGroup (PermissionsClassInterface $ group ): static
93
+ {
94
+ $ this ->group = $ group ;
95
+ return $ this ;
96
+ }
97
+
98
+ /**
99
+ * @inheritDoc
100
+ */
101
+ public function setOther (PermissionsClassInterface $ other ): static
102
+ {
103
+ $ this ->other = $ other ;
104
+ return $ this ;
105
+ }
106
+ }
0 commit comments