Files
lucent-laravel/src/Core/Schema/Data/FieldProp/FieldProp.php
T

37 lines
1.1 KiB
PHP
Raw Normal View History

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) {
2026-01-09 16:54:42 +02:00
"text" => new TextFieldProp(min: 0, max: 0, default: ""),
2026-01-10 02:09:50 +02:00
"relation" => new RelationFieldProp(schemas: [], min: 0, max: 0),
2026-01-08 13:10:18 +02:00
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(
min: $props["min"] ?? 0,
max: $props["max"] ?? 0,
default: $props["default"] ?? "",
),
2026-01-10 02:09:50 +02:00
"relation" => new RelationFieldProp(
schemas: $props["schemas"] ?? [],
min: $props["min"] ?? 0,
max: $props["max"] ?? 0,
),
2026-01-08 13:10:18 +02:00
default => new InvalidFieldProp(),
};
}
}