37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php namespace Lucent\Core\Schema\Data\FieldProp;
|
|
|
|
class FieldProp
|
|
{
|
|
public static function fromType(string $type): IFieldProp
|
|
{
|
|
return match ($type) {
|
|
"text" => new TextFieldProp(min: 0, max: 0, default: ""),
|
|
"relation" => new RelationFieldProp(schemas: [], min: 0, max: 0),
|
|
default => new InvalidFieldProp(),
|
|
};
|
|
}
|
|
|
|
public static function fromDb(string $type, string $propsJson): IFieldProp
|
|
{
|
|
$props = json_decode($propsJson, true);
|
|
return self::fromArray($type, $props);
|
|
}
|
|
|
|
public static function fromArray(string $type, array $props): IFieldProp
|
|
{
|
|
return match ($type) {
|
|
"text" => new TextFieldProp(
|
|
min: $props["min"] ?? 0,
|
|
max: $props["max"] ?? 0,
|
|
default: $props["default"] ?? "",
|
|
),
|
|
"relation" => new RelationFieldProp(
|
|
schemas: $props["schemas"] ?? [],
|
|
min: $props["min"] ?? 0,
|
|
max: $props["max"] ?? 0,
|
|
),
|
|
default => new InvalidFieldProp(),
|
|
};
|
|
}
|
|
}
|