- Removed NULL and added a new Enum instead

This commit is contained in:
Dave Mc Nicoll 2024-06-02 23:02:56 +00:00
parent 72be397a72
commit ba754c6be8
3 changed files with 20 additions and 2 deletions

View File

@ -49,8 +49,12 @@ class Taxus
* @param ...$arguments * @param ...$arguments
* @return bool|null Return TRUE if granted, FALSE if not and NULL if this call should be skipped * @return bool|null Return TRUE if granted, FALSE if not and NULL if this call should be skipped
*/ */
public function granted($name, ...$arguments) : null|bool public function granted(\BackedEnum|string|null $name, ...$arguments) : bool|TaxusGrantEnum
{ {
if ($name === null) {
return true;
}
$name = $name instanceof \BackedEnum ? $name->value : $name; $name = $name instanceof \BackedEnum ? $name->value : $name;
if ( ! isset($this->list[$name]) ) { if ( ! isset($this->list[$name]) ) {

12
src/TaxusGrantEnum.php Normal file
View File

@ -0,0 +1,12 @@
<?php
namespace Taxus;
enum TaxusGrantEnum
{
case Authorized;
case Unauthorized;
case Ignored;
}

View File

@ -12,7 +12,9 @@ trait UserEntityTrait
throw new \Exception("An instance of Taxus must be linked to this object."); throw new \Exception("An instance of Taxus must be linked to this object.");
} }
return $this->taxus->granted($privilegeName, ...$arguments); $grant = $this->taxus->granted($privilegeName, ...$arguments);
return is_bool($grant) ? $grant : $grant === TaxusGrantEnum::Authorized;
} }
public function cannot(string $privilegeName, ...$arguments) : bool public function cannot(string $privilegeName, ...$arguments) : bool