icon === null) { return null; } if ($this->icon instanceof Icon) { return $this->icon; } return Icon::fromString($this->icon); } public static function fromArray(array $data): self { return new self( path: $data['path'], title: $data['title'], routeName: $data['route_name'] ?? '', controllerClass: $data['controller_class'], methodName: $data['method_name'], icon: $data['icon'] ?? null, // Can be string or Icon section: $data['section'] ?? null, order: $data['order'] ?? 0, hidden: $data['hidden'] ?? false, description: $data['description'] ?? null ); } public function toArray(): array { return [ 'path' => $this->path, 'title' => $this->title, 'route_name' => $this->routeName, 'controller_class' => $this->controllerClass, 'method_name' => $this->methodName, 'icon' => $this->icon instanceof Icon ? $this->icon->toString() : $this->icon, 'section' => $this->section, 'order' => $this->order, 'hidden' => $this->hidden, 'description' => $this->description, ]; } public function withTitle(string $title): self { return new self( path: $this->path, title: $title, routeName: $this->routeName, controllerClass: $this->controllerClass, methodName: $this->methodName, icon: $this->icon, section: $this->section, order: $this->order, hidden: $this->hidden, description: $this->description ); } public function withSection(?string $section): self { return new self( path: $this->path, title: $this->title, routeName: $this->routeName, controllerClass: $this->controllerClass, methodName: $this->methodName, icon: $this->icon, section: $section, order: $this->order, hidden: $this->hidden, description: $this->description ); } public function withOrder(int $order): self { return new self( path: $this->path, title: $this->title, routeName: $this->routeName, controllerClass: $this->controllerClass, methodName: $this->methodName, icon: $this->icon, section: $this->section, order: $order, hidden: $this->hidden, description: $this->description ); } public function withHidden(bool $hidden): self { return new self( path: $this->path, title: $this->title, routeName: $this->routeName, controllerClass: $this->controllerClass, methodName: $this->methodName, icon: $this->icon, section: $this->section, order: $this->order, hidden: $hidden, description: $this->description ); } }