- Some minor bug fixes made and redefined constructor to match PHP 8+
This commit is contained in:
		
							parent
							
								
									ba754c6be8
								
							
						
					
					
						commit
						e134e81334
					
				| @ -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"); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -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 ?"); | ||||
|         } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user