Class AuthorizationService
Property Summary
-
$authorizationChecked protected
bool
Track whether or not authorization was checked.
-
$resolver protected
Authorization\Policy\ResolverInterface
Authorization policy resolver.
Method Summary
-
__construct() public
-
applyScope() public
Apply authorization scope conditions/restrictions.
-
authorizationChecked() public
Return a boolean based on whether or not this object has had an authorization operation performed.
-
can() public
Check whether the provided user can perform an action on a resource.
-
canResult() public
Check whether the provided user can perform an action on a resource.
-
getCanHandler() protected
Returns a policy action handler.
-
getScopeHandler() protected
Returns a policy scope action handler.
-
performCheck() protected
Check whether the provided user can perform an action on a resource.
-
resultTypeCheck() protected
Check result type.
-
skipAuthorization() public
Allow for authorization to be skipped for this object.
Method Detail
__construct() ¶ public
__construct(Authorization\Policy\ResolverInterface $resolver)
Parameters
-
Authorization\Policy\ResolverInterface
$resolver Authorization policy resolver.
applyScope() ¶ public
applyScope(Authorization\IdentityInterface|null $user, string $action, mixed $resource): mixed
Apply authorization scope conditions/restrictions.
This method is intended for applying authorization to objects that are then used to access authorized collections of objects. The typical use case for scopes are restricting a query to only return records visible to the current user.
Parameters
-
Authorization\IdentityInterface|null
$user -
string
$action -
mixed
$resource
Returns
mixed
authorizationChecked() ¶ public
authorizationChecked(): bool
Return a boolean based on whether or not this object has had an authorization operation performed.
Returns
bool
can() ¶ public
can(Authorization\IdentityInterface|null $user, string $action, mixed $resource): bool
Check whether the provided user can perform an action on a resource.
This method is intended to allow your application to build conditional logic around authorization checks.
Parameters
-
Authorization\IdentityInterface|null
$user -
string
$action -
mixed
$resource
Returns
bool
canResult() ¶ public
canResult(Authorization\IdentityInterface|null $user, string $action, mixed $resource): Authorization\Policy\ResultInterface
Check whether the provided user can perform an action on a resource.
This method is intended to allow your application to build conditional logic around authorization checks.
Parameters
-
Authorization\IdentityInterface|null
$user -
string
$action -
mixed
$resource
Returns
Authorization\Policy\ResultInterface
getCanHandler() ¶ protected
getCanHandler(mixed $policy, string $action): callable
Returns a policy action handler.
Parameters
-
mixed
$policy Policy object.
-
string
$action Action name.
Returns
callable
Throws
Authorization\Policy\Exception\MissingMethodException
getScopeHandler() ¶ protected
getScopeHandler(mixed $policy, string $action): callable
Returns a policy scope action handler.
Parameters
-
mixed
$policy Policy object.
-
string
$action Action name.
Returns
callable
Throws
Authorization\Policy\Exception\MissingMethodException
performCheck() ¶ protected
performCheck(Authorization\IdentityInterface|null $user, string $action, mixed $resource): boolAuthorization\Policy\ResultInterface
Check whether the provided user can perform an action on a resource.
Parameters
-
Authorization\IdentityInterface|null
$user The user to check permissions for.
-
string
$action The action/operation being performed.
-
mixed
$resource The resource being operated on.
Returns
boolAuthorization\Policy\ResultInterface
resultTypeCheck() ¶ protected
resultTypeCheck(mixed $result): boolAuthorization\Policy\ResultInterface
Check result type.
Parameters
-
mixed
$result Result from policy class instance.
Returns
boolAuthorization\Policy\ResultInterface
Throws
Authorization\Exception\Exception
If $result argument is not a boolean or ResultInterface instance.
skipAuthorization() ¶ public
skipAuthorization(): $this
Allow for authorization to be skipped for this object.
After calling this method the value of authorizationChecked()
should
return true
regardless of whether authorization has been performed or not.
Returns
$this