Compare commits

..

1 Commits

Author SHA1 Message Date
Dave Mc Nicoll
e134e81334 - Some minor bug fixes made and redefined constructor to match PHP 8+ 2025-05-23 19:02:14 +00:00
2 changed files with 17 additions and 19 deletions

View File

@ -2,26 +2,25 @@
namespace Taxus;
use http\Exception\RuntimeException;
class Privilege
{
public string $name;
public string $description;
public mixed $error;
public $success;
public $function;
public ? bool $granted = false;
public function __construct(string $name, string $description = "", ? Callable $function = null, ? Callable $success = null, ? Callable $error = null)
public function __construct(
public string $name,
public string $description = "",
public mixed /* Callable */ $function = null,
public mixed /*? Callable*/ $success = null,
public mixed /*? Callable*/ $error = null,
public ? array $testableArguments = null,
)
{
$this->name = $name;
$this->description = $description;
$this->function = $function;
$this->success = $success;
$this->error = $error;
foreach(array_filter([ 'function' => $function, 'success' => $success, 'error' => $error ]) as $item) {
if ( ! is_callable($item) ) {
throw new RuntimeException("Your {$item} property must be Callable");
}
}
}
}

View File

@ -5,7 +5,7 @@ namespace Taxus;
class Taxus
{
# @ArrayOf Privilege
protected array $list = [];
public array $list = [];
# @ArrayOf PermissionGrantInterface
protected array $gates = [];
@ -28,7 +28,7 @@ class Taxus
public function add(...$privileges) : self
{
foreach($privileges as $item) {
$item = (array) $item;
$item = array_pad((array) $item, 2, null);
if ( ! $item[0] instanceof Privilege ) {
throw new \InvalidArgumentException("First element must be an instance of '" . Privilege::class . "'");
@ -56,7 +56,6 @@ class Taxus
}
$name = $name instanceof \BackedEnum ? $name->value : $name;
if ( ! isset($this->list[$name]) ) {
throw new \InvalidArgumentException("Privilege '{$name}' could not be found. Did you forgot to add it to your Taxus object ?");
}