Bristol SU Support Package
Public Member Functions | Private Member Functions | Private Attributes | List of all members
BristolSU\Support\Permissions\PermissionTester Class Reference
Inheritance diagram for BristolSU\Support\Permissions\PermissionTester:
Inheritance graph
[legend]
Collaboration diagram for BristolSU\Support\Permissions\PermissionTester:
Collaboration graph
[legend]

Public Member Functions

 evaluate (string $ability)
 
 evaluateFor (string $ability, ?User $user=null, ?Group $group=null, ?Role $role=null)
 
 getChain ()
 
 register (Tester $tester, $position=null)
 
- Public Member Functions inherited from BristolSU\Support\Permissions\Contracts\PermissionTester
 evaluateFor (string $ability, ?User $userModel, ?Group $group, ?Role $role)
 
 register (Tester $tester)
 

Private Member Functions

 getPermission (string $ability)
 

Private Attributes

 $testers = []
 

Detailed Description

Test if credentials have permissions

Definition at line 20 of file PermissionTester.php.

Member Function Documentation

◆ evaluate()

BristolSU\Support\Permissions\PermissionTester::evaluate ( string  $ability)

Evaluate a permission using the currently authenticated credentials.

Parameters
string$abilityAbility to test
Returns
bool If the permission is owned by the logged in credentials
Exceptions
ExceptionIf no testers are registered

Implements BristolSU\Support\Permissions\Contracts\PermissionTester.

Definition at line 37 of file PermissionTester.php.

References BristolSU\Support\Permissions\PermissionTester\evaluateFor().

◆ evaluateFor()

BristolSU\Support\Permissions\PermissionTester::evaluateFor ( string  $ability,
?User  $user = null,
?Group  $group = null,
?Role  $role = null 
)

Evaluate a permission for the given credentials.

Parameters
string$abilityAbility to test
User | null$userUser to test the ability on
Group | null$groupGroup to test the ability on
Role | null$roleRole to test the ability on
Returns
bool If the permission is owned
Exceptions
ExceptionIf no testers are registered

Definition at line 62 of file PermissionTester.php.

References BristolSU\Support\Permissions\PermissionTester\getChain().

Referenced by BristolSU\Support\Permissions\PermissionTester\evaluate().

◆ getChain()

BristolSU\Support\Permissions\PermissionTester::getChain ( )

Gets the tester chain

This returns the first registered tester. This tester will have a successor of the first tester, which in turn will have a successor of the second tester etc.

Returns
Tester First registered tester, with the successor chain set
Exceptions
ExceptionIf no testers are registered

Definition at line 77 of file PermissionTester.php.

References BristolSU\Support\Permissions\PermissionTester\$testers.

Referenced by BristolSU\Support\Permissions\PermissionTester\evaluateFor().

◆ getPermission()

BristolSU\Support\Permissions\PermissionTester::getPermission ( string  $ability)
private

Get a permission from the ability

Parameters
string$abilityAbility of the permission
Returns
Permission

Definition at line 95 of file PermissionTester.php.

◆ register()

BristolSU\Support\Permissions\PermissionTester::register ( Tester  $tester,
  $position = null 
)

Register a new tester

Parameters
Tester$testerTester to register
null$positionPosition to insert the tester into. i.e. 0 will put the tester first.

Definition at line 106 of file PermissionTester.php.

Member Data Documentation

◆ $testers

BristolSU\Support\Permissions\PermissionTester::$testers = []
private

The documentation for this class was generated from the following file: