|
11 | 11 | use Temporal\Common\SearchAttributes\SearchAttributeKey\KeywordListValue; |
12 | 12 | use Temporal\Common\SearchAttributes\SearchAttributeKey\KeywordValue; |
13 | 13 | use Temporal\Common\SearchAttributes\SearchAttributeKey\StringValue; |
| 14 | +use Temporal\Common\SearchAttributes\SearchAttributeUpdate\ValueSet; |
14 | 15 |
|
15 | 16 | /** |
16 | 17 | * @psalm-immutable |
| 18 | + * @method ValueSet valueSet(mixed $value) |
17 | 19 | */ |
18 | 20 | abstract class SearchAttributeKey |
19 | 21 | { |
20 | 22 | /** |
21 | | - * @param non-empty-string $key |
| 23 | + * @param non-empty-string $name |
22 | 24 | */ |
23 | 25 | final protected function __construct( |
24 | | - private readonly string $key, |
| 26 | + private readonly string $name, |
25 | 27 | ) {} |
26 | 28 |
|
27 | 29 | /** |
28 | | - * @param non-empty-string $key |
| 30 | + * @param non-empty-string $name |
29 | 31 | */ |
30 | | - public static function forBool(string $key): BoolValue |
| 32 | + public static function forBool(string $name): BoolValue |
31 | 33 | { |
32 | | - return new BoolValue($key); |
| 34 | + return new BoolValue($name); |
33 | 35 | } |
34 | 36 |
|
35 | 37 | /** |
36 | | - * @param non-empty-string $key |
| 38 | + * @param non-empty-string $name |
37 | 39 | */ |
38 | | - public static function forInteger(string $key): IntValue |
| 40 | + public static function forInteger(string $name): IntValue |
39 | 41 | { |
40 | | - return new IntValue($key); |
| 42 | + return new IntValue($name); |
41 | 43 | } |
42 | 44 |
|
43 | 45 | /** |
44 | | - * @param non-empty-string $key |
| 46 | + * @param non-empty-string $name |
45 | 47 | */ |
46 | | - public static function forFloat(string $key): FloatValue |
| 48 | + public static function forFloat(string $name): FloatValue |
47 | 49 | { |
48 | | - return new FloatValue($key); |
| 50 | + return new FloatValue($name); |
49 | 51 | } |
50 | 52 |
|
51 | 53 | /** |
52 | | - * @param non-empty-string $key |
| 54 | + * @param non-empty-string $name |
53 | 55 | */ |
54 | | - public static function forKeyword(string $key): KeywordValue |
| 56 | + public static function forKeyword(string $name): KeywordValue |
55 | 57 | { |
56 | | - return new KeywordValue($key); |
| 58 | + return new KeywordValue($name); |
57 | 59 | } |
58 | 60 |
|
59 | 61 | /** |
60 | | - * @param non-empty-string $key |
| 62 | + * @param non-empty-string $name |
61 | 63 | */ |
62 | | - public static function forString(string $key): StringValue |
| 64 | + public static function forString(string $name): StringValue |
63 | 65 | { |
64 | | - return new StringValue($key); |
| 66 | + return new StringValue($name); |
65 | 67 | } |
66 | 68 |
|
67 | 69 | /** |
68 | | - * @param non-empty-string $key |
| 70 | + * @param non-empty-string $name |
69 | 71 | */ |
70 | | - public static function forDatetime(string $key): DatetimeValue |
| 72 | + public static function forDatetime(string $name): DatetimeValue |
71 | 73 | { |
72 | | - return new DatetimeValue($key); |
| 74 | + return new DatetimeValue($name); |
73 | 75 | } |
74 | 76 |
|
75 | 77 | /** |
76 | | - * @param non-empty-string $key |
| 78 | + * @param non-empty-string $name |
77 | 79 | */ |
78 | | - public static function forKeywordList(string $key): KeywordListValue |
| 80 | + public static function forKeywordList(string $name): KeywordListValue |
79 | 81 | { |
80 | | - return new KeywordListValue($key); |
| 82 | + return new KeywordListValue($name); |
| 83 | + } |
| 84 | + |
| 85 | + public static function for(ValueType $tryFrom, mixed $name): self |
| 86 | + { |
| 87 | + return match ($tryFrom) { |
| 88 | + ValueType::Bool => self::forBool($name), |
| 89 | + ValueType::Int => self::forInteger($name), |
| 90 | + ValueType::Float => self::forFloat($name), |
| 91 | + ValueType::Keyword => self::forKeyword($name), |
| 92 | + ValueType::String => self::forString($name), |
| 93 | + ValueType::Datetime => self::forDatetime($name), |
| 94 | + ValueType::KeywordList => self::forKeywordList($name), |
| 95 | + }; |
| 96 | + } |
| 97 | + |
| 98 | + public function getName(): string |
| 99 | + { |
| 100 | + return $this->name; |
81 | 101 | } |
82 | 102 |
|
83 | 103 | public function valueUnset(): SearchAttributeUpdate |
84 | 104 | { |
85 | 105 | return SearchAttributeUpdate::valueUnset($this->key, $this->getType()); |
86 | 106 | } |
87 | 107 |
|
| 108 | + abstract public function getType(): ValueType; |
| 109 | + |
88 | 110 | protected function prepareValueSet(mixed $value): SearchAttributeUpdate |
89 | 111 | { |
90 | 112 | return SearchAttributeUpdate::valueSet($this->key, $this->getType(), $value); |
91 | 113 | } |
92 | | - |
93 | | - abstract protected function getType(): ValueType; |
94 | 114 | } |
0 commit comments