Skip to content

Commit fdd633c

Browse files
authored
[10.x] Backports InteractsWithData (#56971)
* Backports `InteractsWithData` * fixes static analysis
1 parent 9616f72 commit fdd633c

File tree

3 files changed

+454
-0
lines changed

3 files changed

+454
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
},
128128
"autoload": {
129129
"files": [
130+
"src/Illuminate/Collections/functions.php",
130131
"src/Illuminate/Collections/helpers.php",
131132
"src/Illuminate/Events/functions.php",
132133
"src/Illuminate/Filesystem/functions.php",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}

0 commit comments

Comments
 (0)