layfi-earn/vendor/illuminate/collections/functions.php

28 lines
687 B
PHP
Raw Permalink Normal View History

2025-01-27 20:49:47 +08:00
<?php
namespace Illuminate\Support;
if (! function_exists('Illuminate\Support\enum_value')) {
/**
* Return a scalar value for the given value that might be an enum.
*
* @internal
*
* @template TValue
* @template TDefault
*
* @param TValue $value
* @param TDefault|callable(TValue): TDefault $default
* @return ($value is empty ? TDefault : mixed)
*/
function enum_value($value, $default = null)
{
return match (true) {
$value instanceof \BackedEnum => $value->value,
$value instanceof \UnitEnum => $value->name,
default => $value ?? value($default),
};
}
}