Skip to content

Commit

Permalink
Merge branch '11.x'
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Sep 24, 2024
2 parents 221c5b8 + fed3ae1 commit cca820d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
23 changes: 14 additions & 9 deletions Access/Gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Auth\Access;

use BackedEnum;
use Closure;
use Exception;
use Illuminate\Auth\Access\Events\GateEvaluated;
Expand Down Expand Up @@ -191,14 +192,16 @@ 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
*
* @throws \InvalidArgumentException
*/
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];
}
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*
Expand All @@ -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);

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion Middleware/Authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Auth\Middleware;

use BackedEnum;
use Closure;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Database\Eloquent\Model;
Expand Down Expand Up @@ -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]);
}

Expand Down

0 comments on commit cca820d

Please sign in to comment.