*/ protected array $_fieldTypes = ['id' => Types::STRING]; public function setId($id): void { throw new \LogicException('Use generated id to set a new id to the Snowflake aware entity.'); } /** * Automatically creates a snowflake ID */ public function generateId(): void { if ($this->id === null) { /** @psalm-suppress InvalidPropertyAssignmentValue */ $this->id = Server::get(ISnowflakeGenerator::class)->nextId(); $this->markFieldUpdated('id'); } } public function getCreatedAt(): ?\DateTimeImmutable { return $this->getSnowflake()?->getCreatedAt(); } public function getSnowflake(): ?Snowflake { if ($this->id === null) { return null; } if ($this->snowflake === null) { $this->snowflake = Server::get(ISnowflakeDecoder::class)->decode($this->getId()); } return $this->snowflake; } }