-
Notifications
You must be signed in to change notification settings - Fork 4
/
day.php
55 lines (45 loc) · 1.35 KB
/
day.php
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
<?php
declare(strict_types=1);
use Dbalabka\Enumeration\Examples\Enum\Day;
use Dbalabka\StaticConstructorLoader\StaticConstructorLoader;
if (version_compare(PHP_VERSION, '7.4.0beta', '<')) {
trigger_error('This code requires PHP >= 7.4', E_USER_NOTICE);
return;
}
$composer = require_once(__DIR__ . '/../vendor/autoload.php');
$loader = new StaticConstructorLoader($composer);
class EnumTest
{
private $day;
public function __construct(Day $day) {
$this->day = $day;
}
public function tellItLikeItIs(): void
{
switch ($this->day) {
case Day::$monday:
echo "Mondays are bad.\n";
break;
case Day::$friday:
echo "Fridays are better.\n";
break;
case Day::$saturday:
case Day::$sunday:
echo "Weekends are best.\n";
break;
default:
echo "Midweek days are so-so.\n";
break;
}
}
}
$firstDay = new EnumTest(Day::$monday);
$firstDay->tellItLikeItIs();
$thirdDay = new EnumTest(Day::$wednesday);
$thirdDay->tellItLikeItIs();
$fifthDay = new EnumTest(Day::$friday);
$fifthDay->tellItLikeItIs();
$sixthDay = new EnumTest(Day::$saturday);
$sixthDay->tellItLikeItIs();
$seventhDay = new EnumTest(Day::$sunday);
$seventhDay->tellItLikeItIs();