taxus/src/UserEntityTrait.php

35 lines
865 B
PHP

<?php
namespace Taxus;
trait UserEntityTrait
{
public ? Taxus $taxus;
public function is(string|array $privilegeName, ...$arguments) : bool
{
foreach((array) $privilegeName as $privilege) {
if ( $this->can($privilege, ...$arguments) ) {
return true;
}
}
return false;
}
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);
}
}