8000 [11.x] Improves `Collection` support for enums using `firstWhere()` and `value()` by crynobone · Pull Request #53777 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[11.x] Improves Collection support for enums using firstWhere() and value() #53777

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

Merged
merged 4 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
wip
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Dec 6, 2024
commit f939e3d01f3b51ea027a0d9030456c74342b2711
1 change: 1 addition & 0 deletions src/Illuminate/Collections/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"Illuminate\\Support\\": ""
},
"files": [
"functions.php",
"helpers.php"
]
},
Expand Down
27 changes: 27 additions & 0 deletions src/Illuminate/Collections/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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 transform($value, fn ($value) => match (true) {
$value instanceof \BackedEnum => $value->value,
$value instanceof \UnitEnum => $value->name,

default => $value,
}, $default ?? $value);
}
}
24 changes: 0 additions & 24 deletions src/Illuminate/Support/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,6 @@ function defer(?callable $callback = null, ?string $name = null, bool $always =
}
}

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 transform($value, fn ($value) => match (true) {
$value instanceof \BackedEnum => $value->value,
$value instanceof \UnitEnum => $value->name,

default => $value,
}, $default ?? $value);
}
}

if (! function_exists('Illuminate\Support\php_binary')) {
/**
* Determine the PHP Binary.
Expand Down
Loading
0