Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c0f0b58
feat(session): add BackedEnum support for session keys
binaryfire Dec 22, 2025
1a3ea18
Merge remote-tracking branch 'origin/main' into session-backed-enum-s…
binaryfire Jan 17, 2026
63c417e
feat(session): add UnitEnum support and use enum_value() helper
binaryfire Jan 17, 2026
d07c240
feat(cache): add BackedEnum and UnitEnum support to RateLimiter
binaryfire Jan 17, 2026
3e12e73
Add BackedEnum and UnitEnum support to Gate
binaryfire Jan 17, 2026
b583560
Add BackedEnum and UnitEnum support to Collection
binaryfire Jan 17, 2026
e7b5ee6
Add BackedEnum and UnitEnum support to Cache Repository
binaryfire Jan 17, 2026
568584e
Add BackedEnum and UnitEnum support to Context
binaryfire Jan 17, 2026
39ec1a5
Add BackedEnum and UnitEnum support to Translator replacement values
binaryfire Jan 17, 2026
9f78bba
Add BackedEnum and UnitEnum support to Redis, Filesystem, Eloquent, a…
binaryfire Jan 18, 2026
74ad611
Remove redundant BackedEnum from union types with UnitEnum
binaryfire Jan 18, 2026
23a6815
Remove remaining redundant BackedEnum from union types
binaryfire Jan 18, 2026
02f275b
Add (string) casts for int-backed enum support
binaryfire Jan 18, 2026
795df73
Add enum support to Schedule, Broadcasting, Events, and Collections
binaryfire Jan 18, 2026
dc4fd7f
Add enum support to InteractsWithData and Query Builder
binaryfire Jan 18, 2026
ad15a58
Add enum support to now() and today() helpers
binaryfire Jan 18, 2026
9606812
Remove (string) casts from enum_value() calls
binaryfire Jan 18, 2026
9c38d3c
Use enum_value() for Sanctum token abilities
binaryfire Jan 18, 2026
795cad7
Add enum support to Cookie, Js, ThrottleRequests, and PendingBatch
binaryfire Jan 18, 2026
ea3c509
Add missing Str import to HasApiTokens
binaryfire Jan 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ parameters:
- '#Call to an undefined method Hyperf\\Tappable\\HigherOrderTapProxy#'
- message: '#.*#'
paths:
- src/support/src/Collection.php
- src/core/src/Database/Eloquent/Builder.php
- src/core/src/Database/Eloquent/Collection.php
- src/core/src/Database/Eloquent/Concerns/HasRelationships.php
Expand Down
4 changes: 4 additions & 0 deletions src/auth/src/Access/AuthorizesRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Hypervel\Auth\Contracts\Authenticatable;
use Hypervel\Auth\Contracts\Gate;

use function Hypervel\Support\enum_value;

trait AuthorizesRequests
{
/**
Expand Down Expand Up @@ -39,6 +41,8 @@ public function authorizeForUser(?Authenticatable $user, mixed $ability, mixed $
*/
protected function parseAbilityAndArguments(mixed $ability, mixed $arguments = []): array
{
$ability = enum_value($ability);

if (is_string($ability) && ! str_contains($ability, '\\')) {
return [$ability, $arguments];
}
Expand Down
27 changes: 16 additions & 11 deletions src/auth/src/Access/Gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
use ReflectionException;
use ReflectionFunction;
use ReflectionParameter;
use UnitEnum;

use function Hypervel\Support\enum_value;

class Gate implements GateContract
{
Expand Down Expand Up @@ -58,12 +61,12 @@ public function __construct(
/**
* Determine if a given ability has been defined.
*/
public function has(array|string $ability): bool
public function has(array|UnitEnum|string $ability): bool
{
$abilities = is_array($ability) ? $ability : func_get_args();

foreach ($abilities as $ability) {
if (! isset($this->abilities[$ability])) {
if (! isset($this->abilities[enum_value($ability)])) {
return false;
}
}
Expand Down Expand Up @@ -120,8 +123,10 @@ protected function authorizeOnDemand(bool|Closure|Response $condition, ?string $
*
* @throws InvalidArgumentException
*/
public function define(string $ability, array|callable|string $callback): static
public function define(UnitEnum|string $ability, array|callable|string $callback): static
{
$ability = enum_value($ability);

if (is_array($callback) && isset($callback[0]) && is_string($callback[0])) {
$callback = $callback[0] . '@' . $callback[1];
}
Expand Down Expand Up @@ -227,23 +232,23 @@ public function after(callable $callback): static
/**
* Determine if the given ability should be granted for the current user.
*/
public function allows(string $ability, mixed $arguments = []): bool
public function allows(UnitEnum|string $ability, mixed $arguments = []): bool
{
return $this->check($ability, $arguments);
}

/**
* Determine if the given ability should be denied for the current user.
*/
public function denies(string $ability, mixed $arguments = []): bool
public function denies(UnitEnum|string $ability, mixed $arguments = []): bool
{
return ! $this->allows($ability, $arguments);
}

/**
* Determine if all of the given abilities should be granted for the current user.
*/
public function check(iterable|string $abilities, mixed $arguments = []): bool
public function check(iterable|UnitEnum|string $abilities, mixed $arguments = []): bool
{
return collect($abilities)->every(
fn ($ability) => $this->inspect($ability, $arguments)->allowed()
Expand All @@ -253,15 +258,15 @@ public function check(iterable|string $abilities, mixed $arguments = []): bool
/**
* Determine if any one of the given abilities should be granted for the current user.
*/
public function any(iterable|string $abilities, mixed $arguments = []): bool
public function any(iterable|UnitEnum|string $abilities, mixed $arguments = []): bool
{
return collect($abilities)->contains(fn ($ability) => $this->check($ability, $arguments));
}

/**
* Determine if all of the given abilities should be denied for the current user.
*/
public function none(iterable|string $abilities, mixed $arguments = []): bool
public function none(iterable|UnitEnum|string $abilities, mixed $arguments = []): bool
{
return ! $this->any($abilities, $arguments);
}
Expand All @@ -271,18 +276,18 @@ public function none(iterable|string $abilities, mixed $arguments = []): bool
*
* @throws AuthorizationException
*/
public function authorize(string $ability, mixed $arguments = []): Response
public function authorize(UnitEnum|string $ability, mixed $arguments = []): Response
{
return $this->inspect($ability, $arguments)->authorize();
}

/**
* Inspect the user for the given ability.
*/
public function inspect(string $ability, mixed $arguments = []): Response
public function inspect(UnitEnum|string $ability, mixed $arguments = []): Response
{
try {
$result = $this->raw($ability, $arguments);
$result = $this->raw(enum_value($ability), $arguments);

if ($result instanceof Response) {
return $result;
Expand Down
22 changes: 14 additions & 8 deletions src/auth/src/Contracts/Gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
use Hypervel\Auth\Access\AuthorizationException;
use Hypervel\Auth\Access\Response;
use InvalidArgumentException;
use UnitEnum;

interface Gate
{
/**
* Determine if a given ability has been defined.
*/
public function has(string $ability): bool;
public function has(array|UnitEnum|string $ability): bool;

/**
* Define a new ability.
*/
public function define(string $ability, callable|string $callback): static;
public function define(UnitEnum|string $ability, callable|string $callback): static;

/**
* Define abilities for a resource.
Expand All @@ -43,34 +44,39 @@ public function after(callable $callback): static;
/**
* Determine if the given ability should be granted for the current user.
*/
public function allows(string $ability, mixed $arguments = []): bool;
public function allows(UnitEnum|string $ability, mixed $arguments = []): bool;

/**
* Determine if the given ability should be denied for the current user.
*/
public function denies(string $ability, mixed $arguments = []): bool;
public function denies(UnitEnum|string $ability, mixed $arguments = []): bool;

/**
* Determine if all of the given abilities should be granted for the current user.
*/
public function check(iterable|string $abilities, mixed $arguments = []): bool;
public function check(iterable|UnitEnum|string $abilities, mixed $arguments = []): bool;

/**
* Determine if any one of the given abilities should be granted for the current user.
*/
public function any(iterable|string $abilities, mixed $arguments = []): bool;
public function any(iterable|UnitEnum|string $abilities, mixed $arguments = []): bool;

/**
* Determine if all of the given abilities should be denied for the current user.
*/
public function none(iterable|UnitEnum|string $abilities, mixed $arguments = []): bool;

/**
* Determine if the given ability should be granted for the current user.
*
* @throws AuthorizationException
*/
public function authorize(string $ability, mixed $arguments = []): Response;
public function authorize(UnitEnum|string $ability, mixed $arguments = []): Response;

/**
* Inspect the user for the given ability.
*/
public function inspect(string $ability, mixed $arguments = []): Response;
public function inspect(UnitEnum|string $ability, mixed $arguments = []): Response;

/**
* Get the raw result from the authorization callback.
Expand Down
7 changes: 5 additions & 2 deletions src/auth/src/Middleware/Authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use UnitEnum;

use function Hypervel\Support\enum_value;

class Authorize implements MiddlewareInterface
{
Expand All @@ -28,9 +31,9 @@ public function __construct(protected Gate $gate)
/**
* Specify the ability and models for the middleware.
*/
public static function using(string $ability, string ...$models): string
public static function using(UnitEnum|string $ability, string ...$models): string
{
return static::class . ':' . implode(',', [$ability, ...$models]);
return static::class . ':' . implode(',', [enum_value($ability), ...$models]);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/broadcasting/src/InteractsWithBroadcasting.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
namespace Hypervel\Broadcasting;

use Hyperf\Collection\Arr;
use UnitEnum;

use function Hypervel\Support\enum_value;

trait InteractsWithBroadcasting
{
Expand All @@ -16,8 +19,10 @@ trait InteractsWithBroadcasting
/**
* Broadcast the event using a specific broadcaster.
*/
public function broadcastVia(array|string|null $connection = null): static
public function broadcastVia(UnitEnum|array|string|null $connection = null): static
{
$connection = is_null($connection) ? null : enum_value($connection);

$this->broadcastConnection = is_null($connection)
? [null]
: Arr::wrap($connection);
Expand Down
3 changes: 2 additions & 1 deletion src/broadcasting/src/PendingBroadcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Hypervel\Broadcasting;

use Psr\EventDispatcher\EventDispatcherInterface;
use UnitEnum;

class PendingBroadcast
{
Expand All @@ -20,7 +21,7 @@ public function __construct(
/**
* Broadcast the event using a specific broadcaster.
*/
public function via(?string $connection = null): static
public function via(UnitEnum|string|null $connection = null): static
{
if (method_exists($this->event, 'broadcastVia')) {
$this->event->broadcastVia($connection);
Expand Down
8 changes: 4 additions & 4 deletions src/bus/src/PendingBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Hypervel\Bus;

use BackedEnum;
use Closure;
use Hyperf\Collection\Arr;
use Hyperf\Collection\Collection;
Expand All @@ -17,6 +16,7 @@
use Psr\Container\ContainerInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
use Throwable;
use UnitEnum;

use function Hyperf\Support\value;
use function Hypervel\Support\enum_value;
Expand Down Expand Up @@ -194,9 +194,9 @@ public function name(string $name): static
/**
* Specify the queue connection that the batched jobs should run on.
*/
public function onConnection(string $connection): static
public function onConnection(UnitEnum|string $connection): static
{
$this->options['connection'] = $connection;
$this->options['connection'] = enum_value($connection);

return $this;
}
Expand All @@ -212,7 +212,7 @@ public function connection(): ?string
/**
* Specify the queue that the batched jobs should run on.
*/
public function onQueue(BackedEnum|string|null $queue): static
public function onQueue(UnitEnum|string|null $queue): static
{
$this->options['queue'] = enum_value($queue);

Expand Down
8 changes: 4 additions & 4 deletions src/bus/src/PendingChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Hypervel\Bus;

use BackedEnum;
use Closure;
use DateInterval;
use DateTimeInterface;
Expand All @@ -13,6 +12,7 @@
use Hypervel\Bus\Contracts\Dispatcher;
use Hypervel\Queue\CallQueuedClosure;
use Laravel\SerializableClosure\SerializableClosure;
use UnitEnum;

use function Hyperf\Support\value;
use function Hypervel\Support\enum_value;
Expand Down Expand Up @@ -56,17 +56,17 @@ public function __construct(
/**
* Set the desired connection for the job.
*/
public function onConnection(?string $connection): static
public function onConnection(UnitEnum|string|null $connection): static
{
$this->connection = $connection;
$this->connection = enum_value($connection);

return $this;
}

/**
* Set the desired queue for the job.
*/
public function onQueue(BackedEnum|string|null $queue): static
public function onQueue(UnitEnum|string|null $queue): static
{
$this->queue = enum_value($queue);

Expand Down
10 changes: 5 additions & 5 deletions src/bus/src/PendingDispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Hypervel\Bus;

use BackedEnum;
use DateInterval;
use DateTimeInterface;
use Hyperf\Context\ApplicationContext;
use Hypervel\Bus\Contracts\Dispatcher;
use Hypervel\Cache\Contracts\Factory as CacheFactory;
use Hypervel\Queue\Contracts\ShouldBeUnique;
use UnitEnum;

class PendingDispatch
{
Expand All @@ -30,7 +30,7 @@ public function __construct(
/**
* Set the desired connection for the job.
*/
public function onConnection(BackedEnum|string|null $connection): static
public function onConnection(UnitEnum|string|null $connection): static
{
$this->job->onConnection($connection);

Expand All @@ -40,7 +40,7 @@ public function onConnection(BackedEnum|string|null $connection): static
/**
* Set the desired queue for the job.
*/
public function onQueue(BackedEnum|string|null $queue): static
public function onQueue(UnitEnum|string|null $queue): static
{
$this->job->onQueue($queue);

Expand All @@ -50,7 +50,7 @@ public function onQueue(BackedEnum|string|null $queue): static
/**
* Set the desired connection for the chain.
*/
public function allOnConnection(BackedEnum|string|null $connection): static
public function allOnConnection(UnitEnum|string|null $connection): static
{
$this->job->allOnConnection($connection);

Expand All @@ -60,7 +60,7 @@ public function allOnConnection(BackedEnum|string|null $connection): static
/**
* Set the desired queue for the chain.
*/
public function allOnQueue(BackedEnum|string|null $queue): static
public function allOnQueue(UnitEnum|string|null $queue): static
{
$this->job->allOnQueue($queue);

Expand Down
Loading
Loading