-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathDeleteOriginal.php
More file actions
51 lines (42 loc) · 1.29 KB
/
DeleteOriginal.php
File metadata and controls
51 lines (42 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
namespace SlackPhp\BlockKit\Surfaces\MessageDirective;
use SlackPhp\BlockKit\Exception;
enum DeleteOriginal
{
case DELETE_ORIGINAL;
case DONT_DELETE_ORIGINAL;
/**
* @return array<string, string>
*/
public function toArray(): array
{
return match ($this) {
self::DELETE_ORIGINAL => ['delete_original' => 'true'],
self::DONT_DELETE_ORIGINAL => ['delete_original' => 'false'],
};
}
/**
* @param self|array<string, string>|bool|null $data
* @return static|null
*/
public static function fromValue(self|array|bool|null $data): ?self
{
if ($data instanceof self) {
return $data;
}
if (is_bool($data)) {
return $data ? self::DELETE_ORIGINAL : self::DONT_DELETE_ORIGINAL;
}
if (is_array($data)) {
$data = array_filter($data);
return match ($data) {
['delete_original' => 'true'] => self::DELETE_ORIGINAL,
['delete_original' => 'false'] => self::DONT_DELETE_ORIGINAL,
[] => null,
default => throw new Exception('Invalid Delete Original enum encountered: %s', [json_encode($data)]),
};
}
return null;
}
}