-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Common\SearchAttributes; | ||
|
||
use Temporal\Common\SearchAttributes\SearchAttributeKey\BoolValue; | ||
use Temporal\Common\SearchAttributes\SearchAttributeKey\DatetimeValue; | ||
use Temporal\Common\SearchAttributes\SearchAttributeKey\FloatValue; | ||
use Temporal\Common\SearchAttributes\SearchAttributeKey\IntValue; | ||
use Temporal\Common\SearchAttributes\SearchAttributeKey\KeywordListValue; | ||
use Temporal\Common\SearchAttributes\SearchAttributeKey\KeywordValue; | ||
use Temporal\Common\SearchAttributes\SearchAttributeKey\StringValue; | ||
|
||
/** | ||
* @template-covariant TValue | ||
* @psalm-immutable | ||
*/ | ||
abstract class SearchAttributeKey | ||
{ | ||
/** | ||
* @param non-empty-string $key | ||
* @param TValue $value | ||
*/ | ||
final protected function __construct( | ||
protected readonly string $key, | ||
) {} | ||
|
||
/** | ||
* @param non-empty-string $key | ||
*/ | ||
public static function forBool(string $key): BoolValue | ||
{ | ||
return new BoolValue($key); | ||
} | ||
|
||
/** | ||
* @param non-empty-string $key | ||
*/ | ||
public static function forInteger(string $key): IntValue | ||
{ | ||
return new IntValue($key); | ||
} | ||
|
||
/** | ||
* @param non-empty-string $key | ||
*/ | ||
public static function forFloat(string $key): FloatValue | ||
{ | ||
return new FloatValue($key); | ||
} | ||
|
||
/** | ||
* @param non-empty-string $key | ||
*/ | ||
public static function forKeyword(string $key): KeywordValue | ||
{ | ||
return new KeywordValue($key); | ||
} | ||
|
||
/** | ||
* @param non-empty-string $key | ||
*/ | ||
public static function forString(string $key): StringValue | ||
{ | ||
return new StringValue($key); | ||
} | ||
|
||
public static function forDatetime(string $key): DatetimeValue | ||
{ | ||
return new DatetimeValue($key); | ||
Check failure on line 71 in src/Common/SearchAttributes/SearchAttributeKey.php GitHub Actions / Psalm Validation (PHP 8.3, OS ubuntu-latest)ArgumentTypeCoercion
|
||
} | ||
|
||
/** | ||
* @param non-empty-string $key | ||
* @param iterable<scalar> $value | ||
*/ | ||
public static function forKeywordList(string $key): KeywordListValue | ||
{ | ||
/** @var list<string> $values */ | ||
$values = []; | ||
foreach ($value as $item) { | ||
Check failure on line 82 in src/Common/SearchAttributes/SearchAttributeKey.php GitHub Actions / Psalm Validation (PHP 8.3, OS ubuntu-latest)UndefinedVariable
|
||
$values[] = (string) $item; | ||
} | ||
|
||
return new KeywordListValue($key, $values); | ||
Check failure on line 86 in src/Common/SearchAttributes/SearchAttributeKey.php GitHub Actions / Psalm Validation (PHP 8.3, OS ubuntu-latest)TooManyArguments
|
||
} | ||
|
||
public function valueUnset(): SearchAttributeUpdate {} | ||
Check failure on line 89 in src/Common/SearchAttributes/SearchAttributeKey.php GitHub Actions / Psalm Validation (PHP 8.3, OS ubuntu-latest)InvalidReturnType
|
||
|
||
protected function prepareValueSet(mixed $value): SearchAttributeUpdate { | ||
return SearchAttributeUpdate::valueSet($this->key, $this->getType(), $value); | ||
Check failure on line 92 in src/Common/SearchAttributes/SearchAttributeKey.php GitHub Actions / Psalm Validation (PHP 8.3, OS ubuntu-latest)ImpureMethodCall
|
||
} | ||
|
||
abstract protected function getType(): ValueType; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Common\SearchAttributes\SearchAttributeKey; | ||
|
||
use Temporal\Common\SearchAttributes\SearchAttributeKey; | ||
use Temporal\Common\SearchAttributes\SearchAttributeUpdate; | ||
use Temporal\Common\SearchAttributes\ValueType; | ||
|
||
/** | ||
* @template-extends SearchAttributeKey<bool> | ||
* @psalm-immutable | ||
*/ | ||
final class BoolValue extends SearchAttributeKey | ||
{ | ||
protected function getType(): ValueType | ||
{ | ||
return ValueType::Bool; | ||
} | ||
|
||
public function valueSet(bool $value): SearchAttributeUpdate | ||
{ | ||
return $this->prepareValueSet($value); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Common\SearchAttributes\SearchAttributeKey; | ||
|
||
use DateTimeImmutable; | ||
use DateTimeInterface; | ||
use Temporal\Common\SearchAttributes\SearchAttributeKey; | ||
use Temporal\Common\SearchAttributes\SearchAttributeUpdate; | ||
use Temporal\Common\SearchAttributes\ValueType; | ||
|
||
/** | ||
* @template-extends SearchAttributeKey<DateTimeImmutable> | ||
* @psalm-immutable | ||
*/ | ||
final class DatetimeValue extends SearchAttributeKey | ||
{ | ||
protected function getType(): ValueType | ||
{ | ||
return ValueType::Datetime; | ||
} | ||
|
||
/** | ||
* @param non-empty-string|DateTimeInterface $value | ||
*/ | ||
public function valueSet(string|DateTimeInterface $value): SearchAttributeUpdate | ||
{ | ||
return $this->prepareValueSet(match (true) { | ||
\is_string($value) => new \DateTimeImmutable($value), | ||
$value instanceof \DateTimeImmutable => $value, | ||
default => \DateTimeImmutable::createFromInterface($value), | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Common\SearchAttributes\SearchAttributeKey; | ||
|
||
use Temporal\Common\SearchAttributes\SearchAttributeKey; | ||
use Temporal\Common\SearchAttributes\SearchAttributeUpdate; | ||
use Temporal\Common\SearchAttributes\ValueType; | ||
|
||
/** | ||
* @template-extends SearchAttributeKey<float> | ||
* @psalm-immutable | ||
*/ | ||
final class FloatValue extends SearchAttributeKey | ||
{ | ||
protected function getType(): ValueType | ||
{ | ||
return ValueType::Float; | ||
} | ||
|
||
public function valueSet(float $value): SearchAttributeUpdate | ||
{ | ||
return $this->prepareValueSet($value); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Common\SearchAttributes\SearchAttributeKey; | ||
|
||
use Temporal\Common\SearchAttributes\SearchAttributeKey; | ||
use Temporal\Common\SearchAttributes\SearchAttributeUpdate; | ||
use Temporal\Common\SearchAttributes\ValueType; | ||
|
||
/** | ||
* @template-extends SearchAttributeKey<int> | ||
* @psalm-immutable | ||
*/ | ||
final class IntValue extends SearchAttributeKey | ||
{ | ||
protected function getType(): ValueType | ||
{ | ||
return ValueType::Int; | ||
} | ||
|
||
public function valueSet(int $value): SearchAttributeUpdate | ||
{ | ||
return $this->prepareValueSet($value); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Common\SearchAttributes\SearchAttributeKey; | ||
|
||
use Temporal\Common\SearchAttributes\SearchAttributeKey; | ||
use Temporal\Common\SearchAttributes\SearchAttributeUpdate; | ||
use Temporal\Common\SearchAttributes\ValueType; | ||
|
||
/** | ||
* @template-extends SearchAttributeKey<list<string>> | ||
* @psalm-immutable | ||
*/ | ||
final class KeywordListValue extends SearchAttributeKey | ||
{ | ||
protected function getType(): ValueType | ||
{ | ||
return ValueType::KeywordList; | ||
} | ||
|
||
/** | ||
* @param iterable<string|\Stringable> $value | ||
Check failure on line 23 in src/Common/SearchAttributes/SearchAttributeKey/KeywordListValue.php GitHub Actions / Psalm Validation (PHP 8.3, OS ubuntu-latest)MismatchingDocblockParamType
|
||
*/ | ||
public function valueSet(array $value): SearchAttributeUpdate | ||
{ | ||
$values = []; | ||
foreach ($value as $v) { | ||
$values[] = (string) $v; | ||
} | ||
|
||
return $this->prepareValueSet($values); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Common\SearchAttributes\SearchAttributeKey; | ||
|
||
use Temporal\Common\SearchAttributes\SearchAttributeKey; | ||
use Temporal\Common\SearchAttributes\SearchAttributeUpdate; | ||
use Temporal\Common\SearchAttributes\ValueType; | ||
|
||
/** | ||
* @template-extends SearchAttributeKey<string> | ||
* @psalm-immutable | ||
*/ | ||
final class KeywordValue extends SearchAttributeKey | ||
{ | ||
protected function getType(): ValueType | ||
{ | ||
return ValueType::Keyword; | ||
} | ||
|
||
public function valueSet(string|\Stringable $value): SearchAttributeUpdate | ||
{ | ||
return $this->prepareValueSet((string) $value); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Common\SearchAttributes\SearchAttributeKey; | ||
|
||
use Temporal\Common\SearchAttributes\SearchAttributeKey; | ||
use Temporal\Common\SearchAttributes\SearchAttributeUpdate; | ||
use Temporal\Common\SearchAttributes\ValueType; | ||
|
||
/** | ||
* @template-extends SearchAttributeKey<string> | ||
* @psalm-immutable | ||
*/ | ||
final class StringValue extends SearchAttributeKey | ||
{ | ||
protected function getType(): ValueType | ||
{ | ||
return ValueType::String; | ||
} | ||
|
||
public function valueSet(string|\Stringable $value): SearchAttributeUpdate | ||
{ | ||
return $this->prepareValueSet((string) $value); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Common\SearchAttributes; | ||
|
||
use Temporal\Common\SearchAttributes\SearchAttributeUpdate\ValueSet; | ||
use Temporal\Common\SearchAttributes\SearchAttributeUpdate\ValueUnset; | ||
|
||
/** | ||
* @template-extends SearchAttributeKey<string> | ||
* @psalm-immutable | ||
*/ | ||
abstract class SearchAttributeUpdate | ||
Check failure on line 14 in src/Common/SearchAttributes/SearchAttributeUpdate.php GitHub Actions / Psalm Validation (PHP 8.3, OS ubuntu-latest)InvalidDocblock
|
||
{ | ||
/** | ||
* @param non-empty-string $key | ||
*/ | ||
protected function __construct( | ||
public readonly string $key, | ||
public readonly ValueType $type, | ||
) {} | ||
|
||
public static function valueSet(string $key, ValueType $type, mixed $value): self | ||
{ | ||
return new ValueSet($key, $type, $value); | ||
Check failure on line 26 in src/Common/SearchAttributes/SearchAttributeUpdate.php GitHub Actions / Psalm Validation (PHP 8.3, OS ubuntu-latest)ArgumentTypeCoercion
|
||
} | ||
|
||
public static function valueUnset(string $key, ValueType $type): self | ||
{ | ||
return new ValueUnset($key, $type); | ||
Check failure on line 31 in src/Common/SearchAttributes/SearchAttributeUpdate.php GitHub Actions / Psalm Validation (PHP 8.3, OS ubuntu-latest)ArgumentTypeCoercion
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Common\SearchAttributes\SearchAttributeUpdate; | ||
|
||
use Temporal\Common\SearchAttributes\SearchAttributeKey; | ||
use Temporal\Common\SearchAttributes\SearchAttributeUpdate; | ||
use Temporal\Common\SearchAttributes\ValueType; | ||
|
||
/** | ||
* @template-extends SearchAttributeKey<string> | ||
* @psalm-immutable | ||
*/ | ||
final class ValueSet extends SearchAttributeUpdate | ||
Check failure on line 15 in src/Common/SearchAttributes/SearchAttributeUpdate/ValueSet.php GitHub Actions / Psalm Validation (PHP 8.3, OS ubuntu-latest)InvalidDocblock
|
||
{ | ||
/** | ||
* @param non-empty-string $key | ||
*/ | ||
protected function __construct( | ||
string $key, | ||
ValueType $type, | ||
public readonly mixed $value, | ||
) { | ||
parent::__construct($key, $type); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Common\SearchAttributes\SearchAttributeUpdate; | ||
|
||
use Temporal\Common\SearchAttributes\SearchAttributeKey; | ||
use Temporal\Common\SearchAttributes\SearchAttributeUpdate; | ||
|
||
/** | ||
* @template-extends SearchAttributeKey<string> | ||
* @psalm-immutable | ||
*/ | ||
final class ValueUnset extends SearchAttributeUpdate | ||
{ | ||
} |