@@ 47-73 (lines=27) @@ | ||
44 | * @param bool $requireAll All permissions in the array are required. |
|
45 | * @return bool |
|
46 | */ |
|
47 | public function hasPermission($name, $requireAll = false) |
|
48 | { |
|
49 | if (is_array($name)) { |
|
50 | foreach ($name as $permissionName) { |
|
51 | $hasPermission = $this->hasPermission($permissionName); |
|
52 | ||
53 | if ($hasPermission && !$requireAll) { |
|
54 | return true; |
|
55 | } elseif (!$hasPermission && $requireAll) { |
|
56 | return false; |
|
57 | } |
|
58 | } |
|
59 | ||
60 | // If we've made it this far and $requireAll is FALSE, then NONE of the permissions were found |
|
61 | // If we've made it this far and $requireAll is TRUE, then ALL of the permissions were found. |
|
62 | // Return the value of $requireAll; |
|
63 | return $requireAll; |
|
64 | } else { |
|
65 | foreach ($this->cachedPermissions() as $permission) { |
|
66 | if ($permission->name == $name) { |
|
67 | return true; |
|
68 | } |
|
69 | } |
|
70 | } |
|
71 | ||
72 | return false; |
|
73 | } |
|
74 | ||
75 | public function users() |
|
76 | { |
@@ 96-122 (lines=27) @@ | ||
93 | * @param bool $requireAll All permissions in the array are required. |
|
94 | * @return bool |
|
95 | */ |
|
96 | public function hasPermission($name, $requireAll = false) |
|
97 | { |
|
98 | if (is_array($name)) { |
|
99 | foreach ($name as $permissionName) { |
|
100 | $hasPermission = $this->hasPermission($permissionName); |
|
101 | ||
102 | if ($hasPermission && !$requireAll) { |
|
103 | return true; |
|
104 | } elseif (!$hasPermission && $requireAll) { |
|
105 | return false; |
|
106 | } |
|
107 | } |
|
108 | ||
109 | // If we've made it this far and $requireAll is FALSE, then NONE of the permissions were found |
|
110 | // If we've made it this far and $requireAll is TRUE, then ALL of the permissions were found. |
|
111 | // Return the value of $requireAll; |
|
112 | return $requireAll; |
|
113 | } else { |
|
114 | foreach ($this->cachedPermissions() as $permission) { |
|
115 | if ($permission->name == $name) { |
|
116 | return true; |
|
117 | } |
|
118 | } |
|
119 | } |
|
120 | ||
121 | return false; |
|
122 | } |
|
123 | ||
124 | /** |
|
125 | * Save the inputted permissions. |
@@ 95-122 (lines=28) @@ | ||
92 | * @param bool $requireAll All permissions in the array are required. |
|
93 | * @return bool |
|
94 | */ |
|
95 | public function can($permission, $requireAll = false) |
|
96 | { |
|
97 | if (is_array($permission)) { |
|
98 | foreach ($permission as $permName) { |
|
99 | $hasPerm = $this->can($permName); |
|
100 | ||
101 | if ($hasPerm && !$requireAll) { |
|
102 | return true; |
|
103 | } elseif (!$hasPerm && $requireAll) { |
|
104 | return false; |
|
105 | } |
|
106 | } |
|
107 | ||
108 | // If we've made it this far and $requireAll is FALSE, then NONE of the perms were found |
|
109 | // If we've made it this far and $requireAll is TRUE, then ALL of the perms were found. |
|
110 | // Return the value of $requireAll; |
|
111 | return $requireAll; |
|
112 | } else { |
|
113 | // Validate against the Permission table |
|
114 | foreach ($this->role->cachedPermissions() as $perm) { |
|
115 | if (str_is($permission, $perm->name)) { |
|
116 | return true; |
|
117 | } |
|
118 | } |
|
119 | } |
|
120 | ||
121 | return false; |
|
122 | } |
|
123 | ||
124 | /** |
|
125 | * Checks role(s) and permission(s). |
@@ 156-183 (lines=28) @@ | ||
153 | return false; |
|
154 | } |
|
155 | ||
156 | public function can($permission, $requireAll = false) |
|
157 | { |
|
158 | if (is_array($permission)) { |
|
159 | foreach ($permission as $permName) { |
|
160 | $hasPerm = $this->can($permName); |
|
161 | ||
162 | if ($hasPerm && !$requireAll) { |
|
163 | return true; |
|
164 | } elseif (!$hasPerm && $requireAll) { |
|
165 | return false; |
|
166 | } |
|
167 | } |
|
168 | ||
169 | // If we've made it this far and $requireAll is FALSE, then NONE of the perms were found |
|
170 | // If we've made it this far and $requireAll is TRUE, then ALL of the perms were found. |
|
171 | // Return the value of $requireAll; |
|
172 | return $requireAll; |
|
173 | } else { |
|
174 | // Validate against the Permission table |
|
175 | foreach ($this->role->cachedPermissions() as $perm) { |
|
176 | if (str_is($permission, $perm->name)) { |
|
177 | return true; |
|
178 | } |
|
179 | } |
|
180 | } |
|
181 | ||
182 | return false; |
|
183 | } |
|
184 | ||
185 | public function toArray() |
|
186 | { |