type; } public function getName(): string { return $this->name; } public function getLabel(): string { return $this->label; } public function getDesc(): string { return $this->desc; } public function isRequired(): bool { return $this->required; } public function getAttr(string $key, $default = null) { return $this->attrs[$key] ?? $default; } /** * @param array $array Array for initializing the form element definition * @return RsvFormElementDefinition Definition of the form element for rendering and handling. */ public static function fromArray(array $array): RsvFormElementDefinition { $known = ['type','name','label','desc','required']; $attrs = array_diff_key($array, array_flip($known)); $def = new self( $array['type'], $array['name'], $array['label'], $array['desc'] ?? "", $array['required'] ?? false ); $def->attrs = $attrs; return $def; } public function __construct(string $type, string $name, string $label, string $desc = "", bool $required = false) { $this->type = $type; $this->name = $name; $this->label = $label; $this->desc = $desc; $this->required = $required; } }