| 1 | <?php |
| 2 | |
| 3 | namespace Illuminate\Support; |
| 4 | |
| 5 | if (! function_exists('Illuminate\Support\enum_value')) { |
| 6 | /** |
| 7 | * Return a scalar value for the given value that might be an enum. |
| 8 | * |
| 9 | * @internal |
| 10 | * |
| 11 | * @template TValue |
| 12 | * @template TDefault |
| 13 | * |
| 14 | * @param TValue $value |
| 15 | * @param TDefault|callable(TValue): TDefault $default |
| 16 | * @return ($value is empty ? TDefault : mixed) |
| 17 | */ |
| 18 | function enum_value($value, $default = null) |
| 19 | { |
| 20 | return match (true) { |
| 21 | $value instanceof \BackedEnum => $value->value, |
| 22 | $value instanceof \UnitEnum => $value->name, |
| 23 | |
| 24 | default => $value ?? value($default), |
| 25 | }; |
| 26 | } |
| 27 | } |