12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace App\Enums;
- enum ProjectStatus: int
- {
-
- case OPEN = 1;
-
- case CLOSE = 2;
-
- public function label(): string
- {
- return match ($this) {
- self::OPEN => '开启',
- self::CLOSE => '关闭',
- };
- }
-
- public function value(): int
- {
- return $this->value;
- }
-
- public function is(self $status): bool
- {
- return $this === $status;
- }
-
- public static function fromValue(int $value): ?self
- {
- return match ($value) {
- self::OPEN->value => self::OPEN,
- self::CLOSE->value => self::CLOSE,
- default => null
- };
- }
-
- public static function values(): array
- {
- return array_column(self::cases(), 'value');
- }
-
- public static function all(): array
- {
- return [
- self::OPEN->value => self::OPEN->label(),
- self::CLOSE->value => self::CLOSE->label(),
- ];
- }
- }
|