2026-01-08 13:10:18 +02:00
|
|
|
<?php namespace Lucent\Core\Schema\Data\FieldProp;
|
|
|
|
|
|
|
|
|
|
class FieldProp
|
|
|
|
|
{
|
|
|
|
|
public static function fromType(string $type): IFieldProp
|
|
|
|
|
{
|
|
|
|
|
return match ($type) {
|
|
|
|
|
"text" => new TextFieldProp(
|
|
|
|
|
required: false,
|
|
|
|
|
readonly: false,
|
|
|
|
|
hidden: false,
|
|
|
|
|
min: 0,
|
|
|
|
|
max: 0,
|
|
|
|
|
help: "",
|
|
|
|
|
default: "",
|
|
|
|
|
),
|
|
|
|
|
default => new InvalidFieldProp(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-08 15:19:08 +02:00
|
|
|
public static function fromDb(string $type, string $propsJson): IFieldProp
|
2026-01-08 13:10:18 +02:00
|
|
|
{
|
|
|
|
|
$props = json_decode($propsJson, true);
|
2026-01-08 15:19:08 +02:00
|
|
|
return self::fromArray($type, $props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function fromArray(string $type, array $props): IFieldProp
|
|
|
|
|
{
|
|
|
|
|
return match ($type) {
|
2026-01-08 13:10:18 +02:00
|
|
|
"text" => new TextFieldProp(
|
|
|
|
|
required: $props["required"] ?? false,
|
|
|
|
|
readonly: $props["readonly"] ?? false,
|
|
|
|
|
hidden: $props["hidden"] ?? false,
|
|
|
|
|
min: $props["min"] ?? 0,
|
|
|
|
|
max: $props["max"] ?? 0,
|
|
|
|
|
help: $props["help"] ?? "",
|
|
|
|
|
default: $props["default"] ?? "",
|
|
|
|
|
),
|
|
|
|
|
default => new InvalidFieldProp(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|