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

58 lines
1.7 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-09 16:54:42 +02:00
"help" => $field->help,
2026-01-08 15:19:08 +02:00
"rank" => $field->rank,
2026-01-09 16:54:42 +02:00
"required" => $field->required,
"readonly" => $field->readonly,
"hidden" => $field->hidden,
2026-01-08 23:23:48 +02:00
"translatable" => $field->translatable,
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"),
2026-01-09 16:54:42 +02:00
help: data_get($data, "help"),
2026-01-08 13:10:18 +02:00
schemaId: data_get($data, "schema_id"),
2026-01-08 15:19:08 +02:00
rank: data_get($data, "rank"),
2026-01-09 16:54:42 +02:00
required: data_get($data, "required"),
readonly: data_get($data, "readonly"),
hidden: data_get($data, "hidden"),
2026-01-08 23:23:48 +02:00
translatable: data_get($data, "translatable"),
2026-01-08 15:19:08 +02:00
props: FieldProp::fromDb(
data_get($data, "type"),
data_get($data, "props"),
),
2026-01-08 13:10:18 +02:00
);
}
2026-01-07 23:49:55 +02:00
}