Gate
Implements
Uses
Properties
$userResolver callable
The user resolver callable.
$abilities array
All of the defined abilities.
$policies array
All of the defined policies.
$beforeCallbacks array
All of the registered before callbacks.
$afterCallbacks array
All of the registered after callbacks.
$stringCallbacks array
All of the defined abilities using class@method notation.
$defaultDenialResponse Response |null
The default denial response for gates and policies.
$guessPolicyNamesUsingCallback callable|null
The callback to be used to guess policy names.
Methods
__construct ( Container $container , callable $userResolver , array $abilities , array $policies , array $beforeCallbacks , array $afterCallbacks , callable $guessPolicyNamesUsingCallback ) : void
Create a new gate instance.
Parameters
- $container Container
- $userResolver callable
- $abilities array
- $policies array
- $beforeCallbacks array
- $afterCallbacks array
- $guessPolicyNamesUsingCallback callable|null
has ( $ability ) : bool
Determine if a given ability has been defined.
Parameters
- $ability string|array
allowIf ( $condition , $message , $code ) : Response
Perform an on-demand authorization check. Throw an authorization exception if the condition or callback is false.
Parameters
denyIf ( $condition , $message , $code ) : Response
Perform an on-demand authorization check. Throw an authorization exception if the condition or callback is true.
Parameters
authorizeOnDemand ( $condition , $message , $code , $allowWhenResponseIs ) : Response
Authorize a given condition or callback.
Parameters
define ( $ability , $callback ) : $this
Define a new ability.
Parameters
- $ability string
- $callback callable|array|string
resource ( $name , $class , array $abilities ) : $this
Define abilities for a resource.
Parameters
- $name string
- $class string
- $abilities array|null
buildAbilityCallback ( $ability , $callback ) : Closure
Create the ability callback for a callback string.
Parameters
- $ability string
- $callback string
policy ( $class , $policy ) : $this
Define a policy class for a given class type.
Parameters
- $class string
- $policy string
before ( callable $callback ) : $this
Register a callback to run before all Gate checks.
Parameters
- $callback callable
after ( callable $callback ) : $this
Register a callback to run after all Gate checks.
Parameters
- $callback callable
allows ( $ability , $arguments ) : bool
Determine if the given ability should be granted for the current user.
Parameters
- $ability string
- $arguments array|mixed
denies ( $ability , $arguments ) : bool
Determine if the given ability should be denied for the current user.
Parameters
- $ability string
- $arguments array|mixed
check ( $abilities , $arguments ) : bool
Determine if all of the given abilities should be granted for the current user.
Parameters
- $abilities iterable|string
- $arguments array|mixed
any ( $abilities , $arguments ) : bool
Determine if any one of the given abilities should be granted for the current user.
Parameters
- $abilities iterable|string
- $arguments array|mixed
none ( $abilities , $arguments ) : bool
Determine if all of the given abilities should be denied for the current user.
Parameters
- $abilities iterable|string
- $arguments array|mixed
authorize ( $ability , $arguments ) : Response
Determine if the given ability should be granted for the current user.
Parameters
- $ability string
- $arguments array|mixed
inspect ( $ability , $arguments ) : Response
Inspect the user for the given ability.
Parameters
- $ability string
- $arguments array|mixed
raw ( $ability , $arguments ) : mixed
Get the raw result from the authorization callback.
Parameters
- $ability string
- $arguments array|mixed
canBeCalledWithUser ( $user , $class , $method ) : bool
Determine whether the callback/method can be called with the given user.
Parameters
- $user Authenticatable |null
- $class Closure |string|array
- $method string|null
methodAllowsGuests ( $class , $method ) : bool
Determine if the given class method allows guests.
Parameters
- $class string
- $method string
callbackAllowsGuests ( $callback ) : bool
Determine if the callback allows guests.
Parameters
- $callback callable
parameterAllowsGuests ( $parameter ) : bool
Determine if the given parameter allows guests.
Parameters
- $parameter ReflectionParameter
callAuthCallback ( $user , $ability , array $arguments ) : bool
Resolve and call the appropriate authorization callback.
Parameters
- $user Authenticatable |null
- $ability string
- $arguments array
callBeforeCallbacks ( $user , $ability , array $arguments ) : bool|null
Call all of the before callbacks and return if a result is given.
Parameters
- $user Authenticatable |null
- $ability string
- $arguments array
callAfterCallbacks ( $user , $ability , array $arguments , $result ) : bool|null
Call all of the after callbacks with check result.
Parameters
- $user Authenticatable
- $ability string
- $arguments array
- $result bool
dispatchGateEvaluatedEvent ( $user , $ability , array $arguments , $result ) : void
Dispatch a gate evaluation event.
Parameters
- $user Authenticatable |null
- $ability string
- $arguments array
- $result bool|null
resolveAuthCallback ( $user , $ability , array $arguments ) : callable
Resolve the callable for the given ability and arguments.
Parameters
- $user Authenticatable |null
- $ability string
- $arguments array
getPolicyFor ( $class ) : mixed
Get a policy instance for a given class.
Parameters
- $class object|string
guessPolicyName ( $class ) : array
Guess the policy name for the given class.
Parameters
- $class string
guessPolicyNamesUsing ( callable $callback ) : $this
Specify a callback to be used to guess policy names.
Parameters
- $callback callable
resolvePolicy ( $class ) : mixed
Build a policy class instance of the given type.
Parameters
- $class object|string
resolvePolicyCallback ( $user , $ability , array $arguments , $policy ) : bool|callable
Resolve the callback for a policy check.
Parameters
- $user Authenticatable
- $ability string
- $arguments array
- $policy mixed
callPolicyBefore ( $policy , $user , $ability , $arguments ) : mixed
Call the "before" method on the given policy, if applicable.
Parameters
- $policy mixed
- $user Authenticatable
- $ability string
- $arguments array
callPolicyMethod ( $policy , $method , $user , array $arguments ) : mixed
Call the appropriate method on the given policy.
Parameters
- $policy mixed
- $method string
- $user Authenticatable |null
- $arguments array
formatAbilityToMethod ( $ability ) : string
Format the policy ability into a method name.
Parameters
- $ability string
forUser ( $user ) : static
Get a gate instance for the given user.
Parameters
- $user Authenticatable |mixed
resolveUser ( ) : mixed
Resolve the user from the user resolver.
abilities ( ) : array
Get all of the defined abilities.
policies ( ) : array
Get all of the defined policies.