123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace App\Enums;
- enum ShopServiceStatus: int
- {
-
- case AVAILABLE = 1;
-
- case BUSY = 2;
-
- case UNAVAILABLE = 3;
-
- case MAINTENANCE = 4;
-
- public function label(): string
- {
- return match ($this) {
- self::AVAILABLE => '可预约',
- self::BUSY => '繁忙中',
- self::UNAVAILABLE => '不可预约',
- self::MAINTENANCE => '维护中',
- };
- }
-
- 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::AVAILABLE->value => self::AVAILABLE,
- self::BUSY->value => self::BUSY,
- self::UNAVAILABLE->value => self::UNAVAILABLE,
- self::MAINTENANCE->value => self::MAINTENANCE,
- default => null
- };
- }
-
- public static function values(): array
- {
- return array_column(self::cases(), 'value');
- }
-
- public static function all(): array
- {
- return [
- self::AVAILABLE->value => self::AVAILABLE->label(),
- self::BUSY->value => self::BUSY->label(),
- self::UNAVAILABLE->value => self::UNAVAILABLE->label(),
- self::MAINTENANCE->value => self::MAINTENANCE->label(),
- ];
- }
- }
|