Skip to content

Commit e0f5151

Browse files
committed
convert state ids to records
Signed-off-by: Robert Landers <landers.robert@gmail.com>
1 parent 18e4742 commit e0f5151

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/State/Ids/StateId.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@
3636
use Ramsey\Uuid\UuidInterface;
3737
use RuntimeException;
3838
use Stringable;
39+
use Withinboredom\Record;
3940

4041
use function Bottledcode\DurablePhp\EntityId;
4142
use function Bottledcode\DurablePhp\OrchestrationInstance;
4243

4344
#[ClassNameTypeMap('__type')]
44-
readonly class StateId implements Stringable
45+
readonly class StateId extends Record implements Stringable
4546
{
46-
public function __construct(public string $id) {}
47+
public protected(set) string $id;
4748

4849
public static function fromState(StateInterface $state): self
4950
{
@@ -56,17 +57,24 @@ public static function fromState(StateInterface $state): self
5657

5758
public static function fromInstance(OrchestrationInstance $instance): self
5859
{
59-
return new self("orchestration:{$instance}");
60+
return self::fromArgs(id: "orchestration:{$instance}");
6061
}
6162

6263
public static function fromActivityId(UuidInterface|string $activityId): self
6364
{
64-
return new self("activity:{$activityId}");
65+
return self::fromArgs(id: "activity:{$activityId}");
6566
}
6667

6768
public static function fromEntityId(EntityId $entityId): self
6869
{
69-
return new self("entity:{$entityId}");
70+
return self::fromArgs(id: "entity:{$entityId}");
71+
}
72+
73+
protected static function create(...$args): static
74+
{
75+
$obj = parent::create($args);
76+
$obj->id = $args['id'];
77+
return $obj;
7078
}
7179

7280
public function toActivityId(): string
@@ -81,7 +89,7 @@ public function toActivityId(): string
8189

8290
public static function fromString(string $id): self
8391
{
84-
return new self($id);
92+
return self::fromArgs(id: $id);
8593
}
8694

8795
public function toOrchestrationInstance(): OrchestrationInstance

0 commit comments

Comments
 (0)