37 public function evaluate(
string $ability): bool
43 $user = app(Authentication::class)->getUser();
44 if ($user === null && ($dbUser = app(UserAuthentication::class)->getUser()) !== null) {
45 $user = app(UserRepository::class)->getById($dbUser->control_id);
48 $result = $this->
evaluateFor($ability, $user, app(Authentication::class)->getGroup(), app(Authentication::class)->getRole());
49 return ($result ??
false);
62 public function evaluateFor(
string $ability, ?
User $user = null, ?Group $group = null, ?Role $role = null): bool
65 return ($tester->handle($this->getPermission($ability), $user, $group, $role) ??
false);
79 if (count($this->testers) === 0) {
80 throw new Exception(
'No testers registered');
83 for ($i = 0; $i < (count(
$testers) - 1); $i++) {
97 return app(PermissionRepositoryContract::class)->get($ability);
106 public function register(
Tester $tester, $position = null)
108 if ($position === null) {
109 $this->testers[] = $tester;
111 array_splice($this->testers, $position, 0, [$tester]);
evaluate(string $ability)
evaluateFor(string $ability, ?User $user=null, ?Group $group=null, ?Role $role=null)
getPermission(string $ability)