mirror of
https://github.com/archtechx/enums.git
synced 2025-12-12 21:04:03 +00:00
initial
This commit is contained in:
parent
f9fe9e5cab
commit
41b423da38
11 changed files with 146 additions and 91 deletions
28
src/InvokableCases.php
Normal file
28
src/InvokableCases.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ArchTech\Enums;
|
||||
|
||||
trait InvokableCases
|
||||
{
|
||||
/** Return the enum's value when it's $invoked(). */
|
||||
public function __invoke()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/** Return the enum's value when it's called ::STATICALLY(). */
|
||||
public static function __callStatic($name, $args)
|
||||
{
|
||||
$cases = static::cases();
|
||||
|
||||
foreach ($cases as $case) {
|
||||
if ($case->name === $name) {
|
||||
return $case->value;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exceptions\UndefinedCaseError(static::class, $name);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue