Skip to content

Change Signature of AggregateRootId::fromString #768

Description

@fritz-gerneth

We are using Symfony UUIDs instead of Ramseys'. Unfortunately Symfony's UUID fromString method has slightly different signature than the AggregateRootId interface - they return static instead of self.

So right now we cannot do this:

class MyId extends Uuid implements AggregateRootId
{

}

Instead we have to wrap the Symfony UUID:

class MyId implements AggregateRootId
{
    public function __construct(public readonly Uuid $id)
    {
    }

    public function toString(): string
    {
        return $this->id->toString();
    }

    public static function fromString(string $id): AggregateRootId
    {
        return new self(Uuid::fromString($id));
    }
}

which makes reusing it somewhat cumbersome (e.g. subscriptions ...).

The signature would be:

{
    public function toString(): string;

    public static function fromString(string $id): static;
}

As far as I am concerned this would be a breaking change. Anyone implementing a custom AggregateRootId with the old signature would have to update their implementation. On the up side this would improve typing when calling fromString on a custom root ID (returning the actual implementation, not the interface).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions