@@ -16,58 +16,119 @@ public static function make()
16
16
return new static ;
17
17
}
18
18
19
+ /**
20
+ * Check if the user has access based on roles.
21
+ *
22
+ * @param array $roles
23
+ * @return bool
24
+ */
19
25
private static function hasAccess ($ roles ): bool
20
26
{
21
27
return ! empty (array_intersect ($ roles , session ('role ' )));
22
28
}
23
29
30
+ /**
31
+ * Get the current access status.
32
+ *
33
+ * @return bool
34
+ */
24
35
public function get (): bool
25
36
{
26
37
return $ this ->allowed ;
27
38
}
28
39
40
+ /**
41
+ * Set access allowed for specific roles.
42
+ *
43
+ * @param string $roles
44
+ * @return self
45
+ */
29
46
public function allowedFor (string $ roles = 'all ' ): self
30
47
{
31
48
$ this ->allowed = $ roles === 'all ' || self ::hasAccess (explode (', ' , $ roles ), session ('role ' ));
32
49
33
50
return $ this ;
34
51
}
35
52
53
+ /**
54
+ * Set access not allowed for specific roles.
55
+ *
56
+ * @param string $roles
57
+ * @return self
58
+ */
36
59
public function notAllowedFor (string $ roles = 'all ' ): self
37
60
{
38
61
$ this ->allowed = $ roles !== 'all ' && self ::hasAccess (array_diff (array_keys (Helper::ROLE ), explode (', ' , $ roles )), session ('role ' ));
39
62
40
63
return $ this ;
41
64
}
42
65
66
+ /**
67
+ * Set access allowed for a specific year.
68
+ *
69
+ * @param mixed $year
70
+ * @return self
71
+ */
43
72
public function withYear ($ year ): self
44
73
{
45
74
$ this ->allowed = $ this ->allowed && (session ('year ' ) == $ year );
46
75
47
76
return $ this ;
48
77
}
49
78
79
+ /**
80
+ * Set access allowed if two expressions are equal.
81
+ *
82
+ * @param mixed $expr1
83
+ * @param mixed $expr2
84
+ * @param bool $strict
85
+ * @return self
86
+ */
50
87
public function andEqual ($ expr1 , $ expr2 , $ strict = true ): self
51
88
{
52
89
$ this ->allowed = $ this ->allowed && ($ strict ? $ expr1 === $ expr2 : $ expr1 == $ expr2 );
53
90
54
91
return $ this ;
55
92
}
56
93
94
+ /**
95
+ * Set access allowed if two expressions are not equal.
96
+ *
97
+ * @param mixed $expr1
98
+ * @param mixed $expr2
99
+ * @param bool $strict
100
+ * @return self
101
+ */
57
102
public function andNotEqual ($ expr1 , $ expr2 , $ strict = true ): self
58
103
{
59
104
$ this ->allowed = $ this ->allowed && ($ strict ? $ expr1 !== $ expr2 : $ expr1 != $ expr2 );
60
105
61
106
return $ this ;
62
107
}
63
108
109
+ /**
110
+ * Set access allowed if either of two expressions are equal.
111
+ *
112
+ * @param mixed $expr1
113
+ * @param mixed $expr2
114
+ * @param bool $strict
115
+ * @return self
116
+ */
64
117
public function orEqual ($ expr1 , $ expr2 , $ strict = true ): self
65
118
{
66
119
$ this ->allowed = $ this ->allowed || ($ strict ? $ expr1 === $ expr2 : $ expr1 == $ expr2 );
67
120
68
121
return $ this ;
69
122
}
70
123
124
+ /**
125
+ * Set access allowed if either of two expressions are not equal.
126
+ *
127
+ * @param mixed $expr1
128
+ * @param mixed $expr2
129
+ * @param bool $strict
130
+ * @return self
131
+ */
71
132
public function orNotEqual ($ expr1 , $ expr2 , $ strict = true ): self
72
133
{
73
134
$ this ->allowed = $ this ->allowed || ($ strict ? $ expr1 !== $ expr2 : $ expr1 != $ expr2 );
0 commit comments