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 |
||
54 | |||
55 | /** |
||
56 | * @return StatusInterface |
||
57 | */ |
||
58 | public static function success(): StatusInterface |
||
62 | |||
63 | /** |
||
64 | * @return StatusInterface |
||
65 | */ |
||
66 | public static function fail(): StatusInterface |
||
70 | |||
71 | /** |
||
72 | * @return StatusInterface |
||
73 | */ |
||
74 | public static function error(): StatusInterface |
||
78 | |||
79 | /** |
||
80 | * @param int $value |
||
81 | * @param array $mapping |
||
82 | * |
||
83 | * @return StatusInterface |
||
84 | */ |
||
85 | public static function translate(int $value, array $mapping = self::DEFAULT_MAPPING): StatusInterface |
||
93 | |||
94 | /** |
||
95 | * @return bool |
||
96 | */ |
||
97 | public function isFail(): bool |
||
101 | |||
102 | /** |
||
103 | * @return bool |
||
104 | */ |
||
105 | public function isSuccess(): bool |
||
109 | |||
110 | /** |
||
111 | * @return bool |
||
112 | */ |
||
113 | public function isError(): bool |
||
117 | |||
118 | /** |
||
119 | * @return string |
||
120 | */ |
||
121 | public function __toString(): string |
||
125 | } |
||
126 |