taxus/src/UserEntityTrait.php
2024-06-02 23:02:56 +00:00

24 lines
587 B
PHP

<?php
namespace Taxus;
trait UserEntityTrait
{
public ? Taxus $taxus;
public function can(string $privilegeName, ...$arguments) : bool
{
if (! $this->taxus) {
throw new \Exception("An instance of Taxus must be linked to this object.");
}
$grant = $this->taxus->granted($privilegeName, ...$arguments);
return is_bool($grant) ? $grant : $grant === TaxusGrantEnum::Authorized;
}
public function cannot(string $privilegeName, ...$arguments) : bool
{
return ! $this->can($privilegeName, ...$arguments);
}
}