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 22
33namespace hiqdev \php \billing \customer ;
44
5- enum CustomerState: string
5+ class CustomerState
66{
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+ }
1123
1224 public static function isDeleted (CustomerInterface $ customer ): bool
1325 {
@@ -16,6 +28,23 @@ public static function isDeleted(CustomerInterface $customer): bool
1628
1729 public static function deleted (): CustomerState
1830 {
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' " );
2049 }
2150}
You can’t perform that action at this time.
0 commit comments