field create

This commit is contained in:
2026-01-08 13:10:18 +02:00
parent 4d2497d96f
commit ebccac210a
15 changed files with 318 additions and 18 deletions
+4
View File
@@ -1,5 +1,7 @@
<?php namespace Lucent\Core\Schema\Data;
use Lucent\Core\Schema\Data\FieldProp\IFieldProp;
class Field
{
public function __construct(
@@ -7,5 +9,7 @@ class Field
public string $alias,
public string $name,
public string $type,
public string $schemaId,
public IFieldProp $props,
) {}
}
@@ -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(),
};
}
}
@@ -0,0 +1,3 @@
<?php namespace Lucent\Core\Schema\Data\FieldProp;
interface IFieldProp {}
@@ -0,0 +1,6 @@
<?php namespace Lucent\Core\Schema\Data\FieldProp;
class InvalidFieldProp implements IFieldProp
{
public function __construct() {}
}
@@ -0,0 +1,14 @@
<?php namespace Lucent\Core\Schema\Data\FieldProp;
class TextFieldProp implements IFieldProp
{
public function __construct(
public bool $required,
public bool $readonly,
public bool $hidden,
public string $default,
public int $min,
public int $max,
public string $help,
) {}
}