File tree Expand file tree Collapse file tree 1 file changed +35
-6
lines changed Expand file tree Collapse file tree 1 file changed +35
-6
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace hiqdev \php \billing \customer ;
4
4
5
- enum CustomerState: string
5
+ class CustomerState
6
6
{
7
- case BLOCKED = 'blocked ' ;
8
- case DELETED = 'deleted ' ;
9
- case NEW = 'new ' ;
10
- case OK = 'ok ' ;
7
+ public const BLOCKED = 'blocked ' ;
8
+
9
+ public const DELETED = 'deleted ' ;
10
+
11
+ public const NEW = 'new ' ;
12
+
13
+ public const OK = 'ok ' ;
14
+
15
+ private function __construct (protected string $ state = self ::NEW )
16
+ {
17
+ }
18
+
19
+ public function getName (): string
20
+ {
21
+ return $ this ->state ;
22
+ }
11
23
12
24
public static function isDeleted (CustomerInterface $ customer ): bool
13
25
{
@@ -16,6 +28,23 @@ public static function isDeleted(CustomerInterface $customer): bool
16
28
17
29
public static function deleted (): CustomerState
18
30
{
19
- return self ::DELETED ;
31
+ return new self (self ::DELETED );
32
+ }
33
+
34
+ public static function fromString (string $ name ): self
35
+ {
36
+ $ allowedStates = [
37
+ self ::BLOCKED ,
38
+ self ::DELETED ,
39
+ self ::NEW ,
40
+ self ::OK ,
41
+ ];
42
+ foreach ($ allowedStates as $ state ) {
43
+ if ($ state === $ name ) {
44
+ return new self ($ state );
45
+ }
46
+ }
47
+
48
+ throw new \Exception ("wrong customer state ' $ name' " );
20
49
}
21
50
}
You can’t perform that action at this time.
0 commit comments