3636use Ramsey \Uuid \UuidInterface ;
3737use RuntimeException ;
3838use Stringable ;
39+ use Withinboredom \Record ;
3940
4041use function Bottledcode \DurablePhp \EntityId ;
4142use 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