diff --git a/Access/Gate.php b/Access/Gate.php index 2f0c6c6c..74616484 100644 --- a/Access/Gate.php +++ b/Access/Gate.php @@ -2,6 +2,7 @@ namespace Illuminate\Auth\Access; +use BackedEnum; use Closure; use Exception; use Illuminate\Auth\Access\Events\GateEvaluated; @@ -191,7 +192,7 @@ protected function authorizeOnDemand($condition, $message, $code, $allowWhenResp /** * Define a new ability. * - * @param string $ability + * @param \BackedEnum|string $ability * @param callable|array|string $callback * @return $this * @@ -199,6 +200,8 @@ protected function authorizeOnDemand($condition, $message, $code, $allowWhenResp */ public function define($ability, $callback) { + $ability = $ability instanceof BackedEnum ? $ability->value : $ability; + if (is_array($callback) && isset($callback[0]) && is_string($callback[0])) { $callback = $callback[0].'@'.$callback[1]; } @@ -320,7 +323,7 @@ public function after(callable $callback) /** * Determine if all of the given abilities should be granted for the current user. * - * @param iterable|string $ability + * @param iterable|\BackedEnum|string $ability * @param array|mixed $arguments * @return bool */ @@ -332,7 +335,7 @@ public function allows($ability, $arguments = []) /** * Determine if any of the given abilities should be denied for the current user. * - * @param iterable|string $ability + * @param iterable|\BackedEnum|string $ability * @param array|mixed $arguments * @return bool */ @@ -344,7 +347,7 @@ public function denies($ability, $arguments = []) /** * Determine if all of the given abilities should be granted for the current user. * - * @param iterable|string $abilities + * @param iterable|\BackedEnum|string $abilities * @param array|mixed $arguments * @return bool */ @@ -358,7 +361,7 @@ public function check($abilities, $arguments = []) /** * Determine if any one of the given abilities should be granted for the current user. * - * @param iterable|string $abilities + * @param iterable|\BackedEnum|string $abilities * @param array|mixed $arguments * @return bool */ @@ -370,7 +373,7 @@ public function any($abilities, $arguments = []) /** * Determine if all of the given abilities should be denied for the current user. * - * @param iterable|string $abilities + * @param iterable|\BackedEnum|string $abilities * @param array|mixed $arguments * @return bool */ @@ -382,7 +385,7 @@ public function none($abilities, $arguments = []) /** * Determine if the given ability should be granted for the current user. * - * @param string $ability + * @param \BackedEnum|string $ability * @param array|mixed $arguments * @return \Illuminate\Auth\Access\Response * @@ -396,12 +399,14 @@ public function authorize($ability, $arguments = []) /** * Inspect the user for the given ability. * - * @param string $ability + * @param \BackedEnum|string $ability * @param array|mixed $arguments * @return \Illuminate\Auth\Access\Response */ public function inspect($ability, $arguments = []) { + $ability = $ability instanceof BackedEnum ? $ability->value : $ability; + try { $result = $this->raw($ability, $arguments); @@ -575,7 +580,7 @@ protected function callBeforeCallbacks($user, $ability, array $arguments) * @param \Illuminate\Contracts\Auth\Authenticatable $user * @param string $ability * @param array $arguments - * @param bool $result + * @param bool|null $result * @return bool|null */ protected function callAfterCallbacks($user, $ability, array $arguments, $result) diff --git a/Middleware/Authenticate.php b/Middleware/Authenticate.php index ef1a3f2e..95a16268 100644 --- a/Middleware/Authenticate.php +++ b/Middleware/Authenticate.php @@ -52,7 +52,7 @@ public static function using($guard, ...$others) * * @param \Illuminate\Http\Request $request * @param \Closure $next - * @param string[] ...$guards + * @param string ...$guards * @return mixed * * @throws \Illuminate\Auth\AuthenticationException diff --git a/Middleware/Authorize.php b/Middleware/Authorize.php index 0b6ece4a..22fb4c52 100644 --- a/Middleware/Authorize.php +++ b/Middleware/Authorize.php @@ -2,6 +2,7 @@ namespace Illuminate\Auth\Middleware; +use BackedEnum; use Closure; use Illuminate\Contracts\Auth\Access\Gate; use Illuminate\Database\Eloquent\Model; @@ -29,12 +30,14 @@ public function __construct(Gate $gate) /** * Specify the ability and models for the middleware. * - * @param string $ability + * @param \BackedEnum|string $ability * @param string ...$models * @return string */ public static function using($ability, ...$models) { + $ability = $ability instanceof BackedEnum ? $ability->value : $ability; + return static::class.':'.implode(',', [$ability, ...$models]); }