1 | <?php |
||
9 | class Status |
||
10 | { |
||
11 | private const SCHEDULED = 'scheduled'; |
||
12 | private const POSTPONED = 'postponed'; |
||
13 | private const CANCELLED = 'cancelled'; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $value; |
||
19 | |||
20 | /** |
||
21 | * @var string[] |
||
22 | */ |
||
23 | private const ALLOWED_VALUES = [ |
||
24 | self::SCHEDULED, |
||
25 | self::POSTPONED, |
||
26 | self::CANCELLED, |
||
27 | ]; |
||
28 | |||
29 | private function __construct(string $value) |
||
30 | { |
||
31 | if (!\in_array($value, self::ALLOWED_VALUES, true)) { |
||
32 | throw new InvalidArgumentException('Status does not support the value "' . $value . '"'); |
||
33 | } |
||
34 | $this->value = $value; |
||
35 | } |
||
36 | |||
37 | public static function scheduled(): Status |
||
41 | |||
42 | public static function postponed(): Status |
||
46 | |||
47 | public static function cancelled(): Status |
||
51 | |||
52 | public function toNative(): string |
||
56 | |||
57 | public static function fromNative(string $value): Status |
||
61 | |||
62 | public function equals(Status $status): bool |
||
66 | } |
||
67 |