Documentation

Gate
in package
implements Gate Uses HandlesAuthorization

Interfaces, Classes and Traits

Gate

Table of Contents

$abilities  : array<string|int, mixed>
All of the defined abilities.
$afterCallbacks  : array<string|int, mixed>
All of the registered after callbacks.
$beforeCallbacks  : array<string|int, mixed>
All of the registered before callbacks.
$container  : Container
The container instance.
$policies  : array<string|int, mixed>
All of the defined policies.
$userResolver  : callable
The user resolver callable.
__construct()  : void
Create a new gate instance.
abilities()  : array<string|int, mixed>
Get all of the defined abilities.
after()  : $this
Register a callback to run after all Gate checks.
allows()  : bool
Determine if the given ability should be granted for the current user.
any()  : bool
Determine if any one of the given abilities should be granted for the current user.
authorize()  : Response
Determine if the given ability should be granted for the current user.
before()  : $this
Register a callback to run before all Gate checks.
check()  : bool
Determine if all of the given abilities should be granted for the current user.
define()  : $this
Define a new ability.
denies()  : bool
Determine if the given ability should be denied for the current user.
forUser()  : static
Get a gate instance for the given user.
getPolicyFor()  : mixed
Get a policy instance for a given class.
has()  : bool
Determine if a given ability has been defined.
policies()  : array<string|int, mixed>
Get all of the defined policies.
policy()  : $this
Define a policy class for a given class type.
resolvePolicy()  : mixed
Build a policy class instance of the given type.
resource()  : $this
Define abilities for a resource.
allow()  : Response
Create a new access response.
buildAbilityCallback()  : Closure
Create the ability callback for a callback string.
callAfterCallbacks()  : void
Call all of the after callbacks with check result.
callAuthCallback()  : bool
Resolve and call the appropriate authorization callback.
callBeforeCallbacks()  : bool|null
Call all of the before callbacks and return if a result is given.
callPolicyBefore()  : mixed
Call the "before" method on the given policy, if applicable.
deny()  : void
Throws an unauthorized exception.
formatAbilityToMethod()  : string
Format the policy ability into a method name.
raw()  : mixed
Get the raw result from the authorization callback.
resolveAuthCallback()  : callable
Resolve the callable for the given ability and arguments.
resolvePolicyCallback()  : bool|callable
Resolve the callback for a policy check.
resolveUser()  : mixed
Resolve the user from the user resolver.

Properties

$abilities

All of the defined abilities.

protected array<string|int, mixed> $abilities = []

$afterCallbacks

All of the registered after callbacks.

protected array<string|int, mixed> $afterCallbacks = []

$beforeCallbacks

All of the registered before callbacks.

protected array<string|int, mixed> $beforeCallbacks = []

$policies

All of the defined policies.

protected array<string|int, mixed> $policies = []

$userResolver

The user resolver callable.

protected callable $userResolver

Methods

__construct()

Create a new gate instance.

public __construct(Container $container, callable $userResolver[, array<string|int, mixed> $abilities = [] ][, array<string|int, mixed> $policies = [] ][, array<string|int, mixed> $beforeCallbacks = [] ][, array<string|int, mixed> $afterCallbacks = [] ]) : void
Parameters
$container : Container
$userResolver : callable
$abilities : array<string|int, mixed> = []
$policies : array<string|int, mixed> = []
$beforeCallbacks : array<string|int, mixed> = []
$afterCallbacks : array<string|int, mixed> = []
Return values
void

abilities()

Get all of the defined abilities.

public abilities() : array<string|int, mixed>
Return values
array<string|int, mixed>

after()

Register a callback to run after all Gate checks.

public after(callable $callback) : $this
Parameters
$callback : callable
Return values
$this

allows()

Determine if the given ability should be granted for the current user.

public allows(string $ability[, array<string|int, mixed>|mixed $arguments = [] ]) : bool
Parameters
$ability : string
$arguments : array<string|int, mixed>|mixed = []
Return values
bool

any()

Determine if any one of the given abilities should be granted for the current user.

public any(iteratable<string|int, mixed>|string $abilities[, array<string|int, mixed>|mixed $arguments = [] ]) : bool
Parameters
$abilities : iteratable<string|int, mixed>|string
$arguments : array<string|int, mixed>|mixed = []
Return values
bool

authorize()

Determine if the given ability should be granted for the current user.

public authorize(string $ability[, array<string|int, mixed>|mixed $arguments = [] ]) : Response
Parameters
$ability : string
$arguments : array<string|int, mixed>|mixed = []
Tags
throws
AuthorizationException
Return values
Response

before()

Register a callback to run before all Gate checks.

public before(callable $callback) : $this
Parameters
$callback : callable
Return values
$this

check()

Determine if all of the given abilities should be granted for the current user.

public check(iteratable<string|int, mixed>|string $abilities[, array<string|int, mixed>|mixed $arguments = [] ]) : bool
Parameters
$abilities : iteratable<string|int, mixed>|string
$arguments : array<string|int, mixed>|mixed = []
Return values
bool

define()

Define a new ability.

public define(string $ability, callable|string $callback) : $this
Parameters
$ability : string
$callback : callable|string
Tags
throws
InvalidArgumentException
Return values
$this

denies()

Determine if the given ability should be denied for the current user.

public denies(string $ability[, array<string|int, mixed>|mixed $arguments = [] ]) : bool
Parameters
$ability : string
$arguments : array<string|int, mixed>|mixed = []
Return values
bool

getPolicyFor()

Get a policy instance for a given class.

public getPolicyFor(object|string $class) : mixed
Parameters
$class : object|string
Return values
mixed

has()

Determine if a given ability has been defined.

public has(string|array<string|int, mixed> $ability) : bool
Parameters
$ability : string|array<string|int, mixed>
Return values
bool

policies()

Get all of the defined policies.

public policies() : array<string|int, mixed>
Return values
array<string|int, mixed>

policy()

Define a policy class for a given class type.

public policy(string $class, string $policy) : $this
Parameters
$class : string
$policy : string
Return values
$this

resolvePolicy()

Build a policy class instance of the given type.

public resolvePolicy(object|string $class) : mixed
Parameters
$class : object|string
Return values
mixed

resource()

Define abilities for a resource.

public resource(string $name, string $class[, array<string|int, mixed> $abilities = null ]) : $this
Parameters
$name : string
$class : string
$abilities : array<string|int, mixed> = null
Return values
$this

buildAbilityCallback()

Create the ability callback for a callback string.

protected buildAbilityCallback(string $ability, string $callback) : Closure
Parameters
$ability : string
$callback : string
Return values
Closure

callAfterCallbacks()

Call all of the after callbacks with check result.

protected callAfterCallbacks(Authenticatable $user, string $ability, array<string|int, mixed> $arguments, bool $result) : void
Parameters
$user : Authenticatable
$ability : string
$arguments : array<string|int, mixed>
$result : bool
Return values
void

callAuthCallback()

Resolve and call the appropriate authorization callback.

protected callAuthCallback(Authenticatable $user, string $ability, array<string|int, mixed> $arguments) : bool
Parameters
$user : Authenticatable
$ability : string
$arguments : array<string|int, mixed>
Return values
bool

callBeforeCallbacks()

Call all of the before callbacks and return if a result is given.

protected callBeforeCallbacks(Authenticatable $user, string $ability, array<string|int, mixed> $arguments) : bool|null
Parameters
$user : Authenticatable
$ability : string
$arguments : array<string|int, mixed>
Return values
bool|null

callPolicyBefore()

Call the "before" method on the given policy, if applicable.

protected callPolicyBefore(mixed $policy, Authenticatable $user, string $ability, array<string|int, mixed> $arguments) : mixed
Parameters
$policy : mixed
$user : Authenticatable
$ability : string
$arguments : array<string|int, mixed>
Return values
mixed

deny()

Throws an unauthorized exception.

protected deny([string $message = 'This action is unauthorized.' ]) : void
Parameters
$message : string = 'This action is unauthorized.'
Tags
throws
AuthorizationException
Return values
void

formatAbilityToMethod()

Format the policy ability into a method name.

protected formatAbilityToMethod(string $ability) : string
Parameters
$ability : string
Return values
string

raw()

Get the raw result from the authorization callback.

protected raw(string $ability[, array<string|int, mixed>|mixed $arguments = [] ]) : mixed
Parameters
$ability : string
$arguments : array<string|int, mixed>|mixed = []
Return values
mixed

resolveAuthCallback()

Resolve the callable for the given ability and arguments.

protected resolveAuthCallback(Authenticatable $user, string $ability, array<string|int, mixed> $arguments) : callable
Parameters
$user : Authenticatable
$ability : string
$arguments : array<string|int, mixed>
Return values
callable

resolvePolicyCallback()

Resolve the callback for a policy check.

protected resolvePolicyCallback(Authenticatable $user, string $ability, array<string|int, mixed> $arguments, mixed $policy) : bool|callable
Parameters
$user : Authenticatable
$ability : string
$arguments : array<string|int, mixed>
$policy : mixed
Return values
bool|callable

resolveUser()

Resolve the user from the user resolver.

protected resolveUser() : mixed
Return values
mixed

Search results