58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php namespace Lucent\Core\Schema;
|
|
|
|
use Lucent\Core\Schema\Data\Field;
|
|
use Lucent\Core\Schema\Data\FieldProp\FieldProp;
|
|
use stdClass;
|
|
|
|
class FieldModule
|
|
{
|
|
// public static function fromArray(array $data): Field
|
|
// {
|
|
// return new Field(
|
|
// id: $data["id"],
|
|
// alias: $data["alias"],
|
|
// name: $data["name"],
|
|
// type: $data["type"],
|
|
// );
|
|
// }
|
|
|
|
public static function toDb(Field $field): array
|
|
{
|
|
return [
|
|
"id" => $field->id,
|
|
"alias" => $field->alias,
|
|
"name" => $field->name,
|
|
"type" => $field->type,
|
|
"help" => $field->help,
|
|
"rank" => $field->rank,
|
|
"required" => $field->required,
|
|
"readonly" => $field->readonly,
|
|
"hidden" => $field->hidden,
|
|
"translatable" => $field->translatable,
|
|
"props" => json_encode($field->props),
|
|
"schema_id" => $field->schemaId,
|
|
];
|
|
}
|
|
|
|
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"),
|
|
help: data_get($data, "help"),
|
|
schemaId: data_get($data, "schema_id"),
|
|
rank: data_get($data, "rank"),
|
|
required: data_get($data, "required"),
|
|
readonly: data_get($data, "readonly"),
|
|
hidden: data_get($data, "hidden"),
|
|
translatable: data_get($data, "translatable"),
|
|
props: FieldProp::fromDb(
|
|
data_get($data, "type"),
|
|
data_get($data, "props"),
|
|
),
|
|
);
|
|
}
|
|
}
|