-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
234 additions
and
26 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
use Kwaadpepper\Enum\BaseEnumRoutable; | ||
|
||
/** | ||
* | ||
* @method static self child() | ||
* @method static self adult() | ||
* @method static self senior() | ||
*/ | ||
final class BasicEnum extends BaseEnumRoutable | ||
{ | ||
// | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
use Kwaadpepper\Enum\BaseEnumRoutable; | ||
|
||
/** | ||
* This defines a day type with all | ||
* seven days of the week, include 'none' | ||
* to allow setting an 'undefined' value. | ||
* | ||
* @method static self none() This is used to set 'null' day | ||
* @method static self mon() The first day of the week | ||
* @method static self tue() The second day of the week | ||
* @method static self wed() The third day of the week | ||
* @method static self thu() The fourth day of the week | ||
* @method static self fri() The fifth day of the week | ||
* @method static self sat() The sixth day of the week | ||
* @method static self sun() The last day of the week | ||
*/ | ||
final class Days extends BaseEnumRoutable | ||
{ | ||
protected static function values(): array | ||
{ | ||
return [ | ||
'none' => 1, | ||
'mon' => 1 << 1, | ||
'tue' => 1 << 2, | ||
'wed' => 1 << 3, | ||
'thu' => 1 << 4, | ||
'fri' => 1 << 5, | ||
'sat' => 1 << 6, | ||
'sun' => 1 << 7, | ||
]; | ||
} | ||
|
||
protected static function labels(): array | ||
{ | ||
return [ | ||
'none' => 'None', | ||
'mon' => 'Monday', | ||
'tue' => 'Tuesday', | ||
'wed' => 'Wednesday', | ||
'thu' => 'Thursday', | ||
'fri' => 'Friday', | ||
'sat' => 'Saturday', | ||
'sun' => 'Sunday' | ||
]; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return (string)$this->label; | ||
} | ||
|
||
/** | ||
* Checks if days contain this day | ||
* | ||
* @param int $days | ||
* @return boolean | ||
*/ | ||
public function has(int $days) | ||
{ | ||
return (bool)($this->value & $days); | ||
} | ||
} |
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