-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDays.php
More file actions
66 lines (60 loc) · 1.6 KB
/
Days.php
File metadata and controls
66 lines (60 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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);
}
}