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.
-
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 ...$optionalArgs): 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 -
mixed
...$optionalArgs
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, mixed ...$optionalArgs): 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 -
mixed
...$optionalArgs
Returns
bool
canResult() ¶ public
canResult(Authorization\IdentityInterface|null $user, string $action, mixed $resource, mixed ...$optionalArgs): 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 -
mixed
...$optionalArgs
Returns
Authorization\Policy\ResultInterface
getCanHandler() ¶ protected
getCanHandler(mixed $policy, string $action): Closure
Returns a policy action handler.
Parameters
-
mixed
$policy Policy object.
-
string
$action Action name.
Returns
Closure
Throws
Authorization\Policy\Exception\MissingMethodException
getScopeHandler() ¶ protected
getScopeHandler(mixed $policy, string $action): Closure
Returns a policy scope action handler.
Parameters
-
mixed
$policy Policy object.
-
string
$action Action name.
Returns
Closure
Throws
Authorization\Policy\Exception\MissingMethodException
performCheck() ¶ protected
performCheck(Authorization\IdentityInterface|null $user, string $action, mixed $resource, mixed ...$optionalArgs): Authorization\Policy\ResultInterface|bool
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.
-
mixed
...$optionalArgs Multiple additional arguments which are passed on
Returns
Authorization\Policy\ResultInterface|bool
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