- Removed NULL and added a new Enum instead
This commit is contained in:
		
							parent
							
								
									72be397a72
								
							
						
					
					
						commit
						ba754c6be8
					
				| @ -49,8 +49,12 @@ class Taxus | ||||
|      * @param ...$arguments | ||||
|      * @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; | ||||
| 
 | ||||
|         if ( ! isset($this->list[$name]) ) { | ||||
|  | ||||
							
								
								
									
										12
									
								
								src/TaxusGrantEnum.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/TaxusGrantEnum.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Taxus; | ||||
| 
 | ||||
| enum TaxusGrantEnum | ||||
| { | ||||
|     case Authorized; | ||||
| 
 | ||||
|     case Unauthorized; | ||||
| 
 | ||||
|     case Ignored; | ||||
| } | ||||
| @ -12,7 +12,9 @@ trait UserEntityTrait | ||||
|             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 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user