123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace App\Enums;
- enum ServiceRangeType: int
- {
-
- case CIRCLE = 1;
-
- case POLYGON = 2;
-
- case ADMINISTRATIVE = 3;
-
- public function label(): string
- {
- return match ($this) {
- self::CIRCLE => '圆形范围',
- self::POLYGON => '多边形范围',
- self::ADMINISTRATIVE => '行政区划',
- };
- }
-
- public function value(): int
- {
- return $this->value;
- }
-
- public function is(self $type): bool
- {
- return $this === $type;
- }
-
- public static function fromValue(int $value): ?self
- {
- return match ($value) {
- self::CIRCLE->value => self::CIRCLE,
- self::POLYGON->value => self::POLYGON,
- self::ADMINISTRATIVE->value => self::ADMINISTRATIVE,
- default => null
- };
- }
-
- public static function values(): array
- {
- return array_column(self::cases(), 'value');
- }
-
- public static function all(): array
- {
- return [
- self::CIRCLE->value => self::CIRCLE->label(),
- self::POLYGON->value => self::POLYGON->label(),
- self::ADMINISTRATIVE->value => self::ADMINISTRATIVE->label(),
- ];
- }
- }
|