-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* beans 配置注入支持枚举 * InEnum 验证器支持原生枚举 * 修复 * 修复 * 修复一个类有多个Bean名称时,beans 注入的属性值不正确 * 完善测试 * 修复 * 修复
- Loading branch information
Showing
14 changed files
with
397 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Imi\Util; | ||
|
||
use Imi\Util\Traits\TStaticClass; | ||
|
||
if (\PHP_VERSION_ID >= 80100) | ||
{ | ||
class EnumUtil | ||
{ | ||
use TStaticClass; | ||
|
||
public static function fromName(string $enum, string $case): \UnitEnum | ||
{ | ||
$result = static::tryFromName($enum, $case); | ||
if ($result) | ||
{ | ||
return $result; | ||
} | ||
throw new \ValueError('"' . $case . '" is not a valid name for enum "' . static::class . '"'); | ||
} | ||
|
||
public static function tryFromName(string $enum, string $case): ?\UnitEnum | ||
{ | ||
foreach ($enum::cases() as $c) | ||
{ | ||
if ($c->name === $case) | ||
{ | ||
return $c; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
public static function in(string $enum, $value): bool | ||
{ | ||
foreach ($enum::cases() as $case) | ||
{ | ||
if ($case === $value || ($case->value ?? $case->name) === $value) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.