-
-
Save IMSoP/c17854a20ee2aebd208d1e8c827e3d9e 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
<?php | |
enum WeekDay { | |
case MONDAY(1, 'Mon', 'Monday'); | |
case TUESDAY(2, 'Tue', 'Tuesday'); | |
case WEDNESDAY(3, 'Wed', 'Wednesday'); | |
case THURSDAY(4, 'Thu', 'Thursday'); | |
case FRIDAY(5, 'Fri', 'Friday'); | |
case SATURDAY(6, 'Sat', 'Saturday'); | |
case SUNDAY(7, 'Sun', 'Sunday'); | |
private function __construct(private int $num, private string $short, private string $long) {} | |
public function getNum(): int { | |
return $this->num; | |
} | |
public function getShort(): string { | |
return $this->short; | |
} | |
public function getLong(): string { | |
return $this->long; | |
} | |
} |
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
<?php | |
enum WeekDay { | |
case MONDAY; | |
case TUESDAY; | |
case WEDNESDAY; | |
case THURSDAY; | |
case FRIDAY; | |
case SATURDAY; | |
case SUNDAY; | |
public function getNum(): int { | |
return match($this) { | |
self::MONDAY => 1, | |
self::TUESDAY => 2, | |
self::WEDNESDAY => 3, | |
self::THURSDAY => 4, | |
self::FRIDAY => 5, | |
self::SATURDAY => 6, | |
self::SUNDAY => 7 | |
}; | |
} | |
public function getShort(): string { | |
return match($this) { | |
self::MONDAY => 'Mon', | |
self::TUESDAY => 'Tue', | |
self::WEDNESDAY => 'Wed', | |
self::THURSDAY => 'Thu', | |
self::FRIDAY => 'Fri', | |
self::SATURDAY => 'Sat', | |
self::SUNDAY => 'Sun' | |
}; | |
} | |
public function getLong(): string { | |
return match($this) { | |
self::MONDAY => 'Monday', | |
self::TUESDAY => 'Tuesday', | |
self::WEDNESDAY => 'Wednesday', | |
self::THURSDAY => 'Thursday', | |
self::FRIDAY => 'Friday', | |
self::SATURDAY => 'Saturday', | |
self::SUNDAY => 'Sunday' | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment