12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace App\Enums;
- enum ProjectType: int
- {
-
- case VISIT = 1;
-
- case OVERTIME = 2;
-
- public function label(): string
- {
- return match ($this) {
- self::VISIT => '上门',
- self::OVERTIME => '加钟',
- };
- }
-
- 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::VISIT->value => self::VISIT,
- self::OVERTIME->value => self::OVERTIME,
- default => null
- };
- }
-
- public static function values(): array
- {
- return array_column(self::cases(), 'value');
- }
-
- public static function all(): array
- {
- return [
- self::VISIT->value => self::VISIT->label(),
- self::OVERTIME->value => self::OVERTIME->label(),
- ];
- }
- }
|