1 | <?php |
||
15 | trait EnsuranceTrait |
||
16 | { |
||
17 | /** |
||
18 | * @var mixed |
||
19 | */ |
||
20 | private $value; |
||
21 | /** |
||
22 | * @var bool |
||
23 | */ |
||
24 | private $ensured = true; |
||
25 | /** |
||
26 | * @var Throwable|null |
||
27 | */ |
||
28 | private $throwable; |
||
29 | |||
30 | /** |
||
31 | * @throws Throwable |
||
32 | */ |
||
33 | public function __destruct() |
||
39 | |||
40 | /** |
||
41 | * @param callable $callback |
||
42 | * |
||
43 | * @return self |
||
44 | */ |
||
45 | final public function is(callable $callback): self |
||
55 | |||
56 | /** |
||
57 | * @param string $type |
||
58 | * |
||
59 | * @return self |
||
60 | * @throws Exception |
||
61 | */ |
||
62 | final public function isTypeOf(string $type): self |
||
68 | |||
69 | /** |
||
70 | * @param mixed $value |
||
71 | * |
||
72 | * @return mixed |
||
73 | */ |
||
74 | final public function then($value) |
||
78 | |||
79 | /** |
||
80 | * @param mixed $value |
||
81 | * |
||
82 | * @return mixed |
||
83 | */ |
||
84 | final public function else($value) |
||
88 | |||
89 | /** |
||
90 | * @param mixed $value |
||
91 | * |
||
92 | * @return Either |
||
93 | */ |
||
94 | final public function either($value): Either |
||
98 | |||
99 | /** |
||
100 | * @param mixed $default |
||
101 | * |
||
102 | * @return mixed |
||
103 | */ |
||
104 | final public function get($default = null) |
||
108 | |||
109 | /** |
||
110 | * @param bool $condition |
||
111 | * |
||
112 | * @return self |
||
113 | */ |
||
114 | final protected function ensure(bool $condition): self |
||
120 | |||
121 | /** |
||
122 | * @return bool |
||
123 | */ |
||
124 | final public function isEnsured(): bool |
||
128 | |||
129 | /** |
||
130 | * @return self |
||
131 | */ |
||
132 | final public function disregardThrowable(): self |
||
138 | |||
139 | /** |
||
140 | * @return Throwable|null |
||
141 | */ |
||
142 | final public function releaseThrowable(): ?Throwable |
||
150 | |||
151 | /** |
||
152 | * @param EnsuranceInterface $ensurance |
||
153 | * |
||
154 | * @return self |
||
155 | */ |
||
156 | final public function transferEnsurance(EnsuranceInterface $ensurance): self |
||
168 | |||
169 | /** |
||
170 | * @param string $message |
||
171 | * @param mixed ...$args |
||
172 | * |
||
173 | * @return self |
||
174 | */ |
||
175 | final public function orThrow(string $message, ...$args): self |
||
183 | |||
184 | /** |
||
185 | * @return bool |
||
186 | */ |
||
187 | final public function hasThrowable(): bool |
||
191 | |||
192 | /** |
||
193 | * @param Throwable $throwable |
||
194 | * |
||
195 | * @return self |
||
196 | * @deprecated Use "orThrowWith" instead |
||
197 | * |
||
198 | */ |
||
199 | final public function setThrowable(Throwable $throwable): self |
||
203 | |||
204 | /** |
||
205 | * @param Throwable $throwable |
||
206 | * |
||
207 | * @return self |
||
208 | */ |
||
209 | final public function orThrowWith(Throwable $throwable): self |
||
217 | |||
218 | /** |
||
219 | * @return Throwable|null |
||
220 | */ |
||
221 | final public function getThrowable(): ?Throwable |
||
225 | } |
||
226 |