Skip to content

Support Laravel 12 #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"require": {
"php": "^8",
"composer/class-map-generator": "^1",
"illuminate/contracts": "^9 || ^10 || ^11",
"illuminate/support": "^9 || ^10 || ^11",
"illuminate/contracts": "^9 || ^10 || ^11 || ^12",
"illuminate/support": "^9 || ^10 || ^11 || ^12",
"laminas/laminas-code": "^3.4 || ^4",
"nikic/php-parser": "^4.13.2 || ^5"
},
Expand Down
21 changes: 17 additions & 4 deletions src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use TijsVerkoyen\CssToInlineStyles\Css\Rule\Rule;

/**
* @template TValue
* @template-covariant TValue
*
* @implements Arrayable<array-key, mixed>
*/
Expand Down Expand Up @@ -77,7 +78,10 @@ public static function __set_state(array $enum): static
/**
* Make a new instance from an enum value.
*
* @param TValue $enumValue
* @param TValue $enumValue
*
* @return static<TValue>
* @throws InvalidEnumMemberException
*/
public static function fromValue(mixed $enumValue): static
{
Expand All @@ -103,7 +107,10 @@ protected static function getReflection(): \ReflectionClass
/**
* Make an enum instance from a given key.
*
* @throws \BenSampo\Enum\Exceptions\InvalidEnumKeyException
* @param string $key
* @return static
* @throws InvalidEnumKeyException
* @throws InvalidEnumMemberException
*/
public static function fromKey(string $key): static
{
Expand Down Expand Up @@ -213,14 +220,20 @@ public static function getInstances(): array
);
}

/** Attempt to instantiate a new Enum using the given key or value. */
/** Attempt to instantiate a new Enum using the given key or value.
* @param mixed $enumKeyOrValue
*
* @return static<TValue>|null
* @throws InvalidEnumMemberException
*/
public static function coerce(mixed $enumKeyOrValue): ?static
{
if ($enumKeyOrValue === null) {
return null;
}

if ($enumKeyOrValue instanceof static) {
/** @var static<TValue> */
return $enumKeyOrValue;
}

Expand Down