initial
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Dynamic definition of the element to be rendered or handled.
|
||||
*/
|
||||
class RsvFormElementDefinition {
|
||||
public string $type;
|
||||
public string $name;
|
||||
public string $label;
|
||||
public string $desc;
|
||||
public bool $required;
|
||||
public array $attrs = [];
|
||||
|
||||
public function getType(): string {
|
||||
return $this->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<int,mixed> $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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user