field create
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?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(),
|
||||
};
|
||||
}
|
||||
|
||||
public static function fromDb(string $propsJson): IFieldProp
|
||||
{
|
||||
$props = json_decode($propsJson, true);
|
||||
return match ($props["type"]) {
|
||||
"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(),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user