$pages Páginas donde aplicar: ['all'], ['home', 'posts'], etc. * @param bool $enabled Si el snippet está activo * @param int $order Orden de carga (menor = primero) */ public function __construct( public readonly string $id, public readonly string $name, public readonly string $description, public readonly string $css, public readonly string $type, public readonly array $pages, public readonly bool $enabled, public readonly int $order ) {} /** * Factory desde array (formulario o API) * * @param array $data Datos del formulario * @return self */ public static function fromArray(array $data): self { return new self( id: $data['id'] ?? '', name: $data['name'] ?? '', description: $data['description'] ?? '', css: $data['css'] ?? '', type: $data['type'] ?? 'deferred', pages: $data['pages'] ?? ['all'], enabled: (bool)($data['enabled'] ?? true), order: (int)($data['order'] ?? 100) ); } /** * Convierte a array para persistencia * * @return array */ public function toArray(): array { return [ 'id' => $this->id, 'name' => $this->name, 'description' => $this->description, 'css' => $this->css, 'type' => $this->type, 'pages' => $this->pages, 'enabled' => $this->enabled, 'order' => $this->order, ]; } }