Authorizer
Introduction
The \Anomaly\Streams\Platform\Support\Authorizer
class allows you to easily add permissions
logic to your application.
By default the users module handles permissions management.{.note}
Basic Usage
authorize
The authorize
method allows you to authorize a user
against a permission
key. If no user
is provided the currently logged in user will be used.
Permissions are generally hinted by their addon's dot namespace
and formatted like {namespace}::stream.action
.
If a
permission
does not exist the authorizer will pass.{.notice}
$authorizer = app(\Anomaly\Streams\Platform\Support\Authorizer::class);
if ($authorizer->authorize('anomaly.module.pages::pages.write', auth()->user())) {
// Do something special.
}
authorizeAll
The authorizeAll
method allows you to authorize a user
against all permission
keys in the provided array. If no user
is provided the currently logged in user will be used.
Permissions are generally hinted by their addon's dot namespace
and formatted like {namespace}::stream.action
.
If no existing
permission
keys were passed the authorizer will pass.{.notice}
$authorizer = app(\Anomaly\Streams\Platform\Support\Authorizer::class);
if ($authorizer->authorizeAll(array $permissions)) {
// Do something special.
}
authorizeRole
The authorizeRole
method allows you to authorize a user
against a role
. If no user
is provided the currently logged in user will be used.
use Anomaly\Streams\Platform\User\Contract\RoleInterface;
$authorizer = app(\Anomaly\Streams\Platform\Support\Authorizer::class);
if ($authorizer->authorizeRole(RoleInterface $role, auth()->user())) {
// Do something special.
}
authorizeRoles
The authorizeAnyRole
method allows you to authorize a user
against any roles
in a collection. If no user
is provided the currently logged in user will be used.
$authorizer = app(\Anomaly\Streams\Platform\Support\Authorizer::class);
if ($authorizer->authorizeRoles($roles)) {
// Do something special.
}
authorizeRoles
The authorizeAnyRole
method allows you to authorize a user
against any roles
in a collection. If no user
is provided the currently logged in user will be used.
$authorizer = app(\Anomaly\Streams\Platform\Support\Authorizer::class);
if ($authorizer->authorizeRoles($roles)) {
// Do something special.
}