1 | <?php |
||
11 | final class Status implements StatusInterface |
||
12 | { |
||
13 | public const DEFAULT_MAPPING = [ |
||
14 | -1 => self::STATUS_ERROR, |
||
15 | 0 => self::STATUS_FAIL, |
||
16 | 1 => self::STATUS_SUCCESS |
||
17 | ]; |
||
18 | |||
19 | /** |
||
20 | * @var StatusInterface[] |
||
21 | */ |
||
22 | private static $instances = []; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | private $status; |
||
28 | |||
29 | /** |
||
30 | * Status constructor. |
||
31 | * |
||
32 | * @param string $status |
||
33 | */ |
||
34 | private function __construct(string $status) |
||
38 | |||
39 | /** |
||
40 | * @param string $status |
||
41 | * |
||
42 | * @return StatusInterface |
||
43 | */ |
||
44 | public static function instance(string $status): StatusInterface |
||
53 | |||
54 | /** |
||
55 | * @return StatusInterface |
||
56 | */ |
||
57 | public static function success(): StatusInterface |
||
61 | |||
62 | /** |
||
63 | * @return StatusInterface |
||
64 | */ |
||
65 | public static function fail(): StatusInterface |
||
69 | |||
70 | /** |
||
71 | * @return StatusInterface |
||
72 | */ |
||
73 | public static function error(): StatusInterface |
||
77 | |||
78 | /** |
||
79 | * @param int $value |
||
80 | * @param array $mapping |
||
81 | * |
||
82 | * @return StatusInterface |
||
83 | */ |
||
84 | public static function translate(int $value, array $mapping = self::DEFAULT_MAPPING): StatusInterface |
||
92 | |||
93 | /** |
||
94 | * @return bool |
||
95 | */ |
||
96 | public function isFail(): bool |
||
100 | |||
101 | /** |
||
102 | * @return bool |
||
103 | */ |
||
104 | public function isSuccess(): bool |
||
108 | |||
109 | /** |
||
110 | * @return bool |
||
111 | */ |
||
112 | public function isError(): bool |
||
116 | |||
117 | /** |
||
118 | * @return string |
||
119 | */ |
||
120 | public function __toString(): string |
||
124 | } |
||
125 |