WIP uploading files
This commit is contained in:
@@ -2,59 +2,39 @@
|
||||
|
||||
namespace Lucent\Schema;
|
||||
|
||||
use Lucent\Data\Schema;
|
||||
use Lucent\LucentException;
|
||||
use Lucent\Primitive\Collection;
|
||||
|
||||
class SchemaService
|
||||
{
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
public function __construct() {}
|
||||
|
||||
public function fromArray(array $schemaArr): Schema
|
||||
{
|
||||
|
||||
return match ($schemaArr["type"]) {
|
||||
"collection" => new CollectionSchema(
|
||||
name: $schemaArr["name"],
|
||||
label: $schemaArr["label"],
|
||||
visible: $schemaArr["visible"] ?? [],
|
||||
groups: $schemaArr["groups"] ?? [],
|
||||
fields: (new Collection($schemaArr["fields"]))->map([$this, 'mapFields']),
|
||||
isEntry: $schemaArr["isEntry"] ?? false,
|
||||
color: $schemaArr["color"] ?? "",
|
||||
sortBy: $schemaArr["sortBy"] ?? "-_sys.updatedAt",
|
||||
cardTitle: $schemaArr["titleTemplate"] ?? $schemaArr["cardTitle"] ?? null,
|
||||
cardImage: $schemaArr["cardImage"] ?? null,
|
||||
revisions: $schemaArr["revisions"] ?? 0,
|
||||
read: $schemaArr["read"] ?? [],
|
||||
write: $schemaArr["write"] ?? [],
|
||||
),
|
||||
"files" => new FilesSchema(
|
||||
name: $schemaArr["name"],
|
||||
label: $schemaArr["label"],
|
||||
fields: (new Collection($schemaArr["fields"]))->map([$this, 'mapFields']),
|
||||
disk: $schemaArr["disk"] ?? "lucent",
|
||||
path: $schemaArr["path"] ?? $schemaArr["name"],
|
||||
groups: $schemaArr["groups"] ?? [],
|
||||
isEntry: $schemaArr["isEntry"] ?? false,
|
||||
sortBy: $schemaArr["sortBy"] ?? "-_sys.updatedAt",
|
||||
color: $schemaArr["color"] ?? "",
|
||||
cardTitle: $schemaArr["titleTemplate"] ?? $schemaArr["cardTitle"] ?? null,
|
||||
cardImage: $schemaArr["cardImage"] ?? null,
|
||||
revisions: $schemaArr["revisions"] ?? 0,
|
||||
read: $schemaArr["read"] ?? [],
|
||||
write: $schemaArr["write"] ?? [],
|
||||
)
|
||||
};
|
||||
|
||||
return new Schema(
|
||||
name: $schemaArr["name"],
|
||||
label: $schemaArr["label"],
|
||||
visible: $schemaArr["visible"] ?? [],
|
||||
groups: $schemaArr["groups"] ?? [],
|
||||
fields: Collection::make($schemaArr["fields"])->map([
|
||||
$this,
|
||||
"mapFields",
|
||||
]),
|
||||
isEntry: $schemaArr["isEntry"] ?? false,
|
||||
color: $schemaArr["color"] ?? "",
|
||||
sortBy: $schemaArr["sortBy"] ?? "-_sys.updatedAt",
|
||||
cardTitle: $schemaArr["titleTemplate"] ??
|
||||
($schemaArr["cardTitle"] ?? null),
|
||||
cardImage: $schemaArr["cardImage"] ?? null,
|
||||
revisions: $schemaArr["revisions"] ?? 0,
|
||||
read: $schemaArr["read"] ?? [],
|
||||
write: $schemaArr["write"] ?? [],
|
||||
);
|
||||
}
|
||||
|
||||
public function mapFields(array $field): FieldInterface
|
||||
{
|
||||
|
||||
$schemaFields = [
|
||||
\Lucent\Schema\Ui\Checkbox::class,
|
||||
\Lucent\Schema\Ui\Color::class,
|
||||
@@ -70,16 +50,22 @@ class SchemaService
|
||||
\Lucent\Schema\Ui\Text::class,
|
||||
\Lucent\Schema\Ui\Textarea::class,
|
||||
];
|
||||
$ui = collect($schemaFields)->filter(function ($className) use ($field) {
|
||||
return str_ends_with(strtolower($className), "\\" . strtolower($field["ui"]));
|
||||
})->first();
|
||||
$ui = collect($schemaFields)
|
||||
->filter(function ($className) use ($field) {
|
||||
return str_ends_with(
|
||||
strtolower($className),
|
||||
"\\" . strtolower($field["ui"]),
|
||||
);
|
||||
})
|
||||
->first();
|
||||
|
||||
if (empty($ui)) {
|
||||
throw new LucentException("Field UI " . $field["ui"] . " not found");
|
||||
throw new LucentException(
|
||||
"Field UI " . $field["ui"] . " not found",
|
||||
);
|
||||
}
|
||||
|
||||
unset($field["ui"]);
|
||||
return new $ui(...$field);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user