Files
lucent-laravel/src/Core/Schema/FieldModule.php
T

43 lines
1.1 KiB
PHP
Raw Normal View History

2026-01-07 23:49:55 +02:00
<?php namespace Lucent\Core\Schema;
use Lucent\Core\Schema\Data\Field;
2026-01-08 13:10:18 +02:00
use Lucent\Core\Schema\Data\FieldProp\FieldProp;
use stdClass;
2026-01-07 23:49:55 +02:00
class FieldModule
{
2026-01-08 13:10:18 +02:00
// public static function fromArray(array $data): Field
// {
// return new Field(
// id: $data["id"],
// alias: $data["alias"],
// name: $data["name"],
// type: $data["type"],
// );
// }
2026-01-07 23:49:55 +02:00
public static function toDb(Field $field): array
{
return [
"id" => $field->id,
"alias" => $field->alias,
"name" => $field->name,
"type" => $field->type,
2026-01-08 13:10:18 +02:00
"props" => json_encode($field->props),
"schema_id" => $field->schemaId,
2026-01-07 23:49:55 +02:00
];
}
2026-01-08 13:10:18 +02:00
public static function fromDb(stdClass $data): Field
{
return new Field(
id: data_get($data, "id"),
alias: data_get($data, "alias"),
name: data_get($data, "name"),
type: data_get($data, "type"),
schemaId: data_get($data, "schema_id"),
props: FieldProp::fromDb(data_get($data, "props")),
);
}
2026-01-07 23:49:55 +02:00
}