Last active
September 17, 2021 21:11
-
-
Save phuclh/17f693d8b6ee3c4b5671fb93366c15e9 to your computer and use it in GitHub Desktop.
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
abstract class BaseEnum | |
{ | |
protected static array $options = []; | |
public static function options(): array | |
{ | |
if (count(static::$options)) { | |
return static::$options; | |
} | |
foreach ((new ReflectionClass(new static))->getConstants() as $constant) { | |
static::$options[$constant] = Str::title(str_replace('-', ' ', $constant)); | |
} | |
return static::$options; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: