id = $id; } public function getId(): int { return $this->id; } /** * 验证ID是否有效 */ public function isValid(): bool { return $this->id > 0; } /** * 从路由参数创建实例 */ public static function fromRoute(int $id): self { return new self($id); } }