fixing multiple references

This commit is contained in:
2024-08-27 12:24:51 +03:00
parent ffc39f078d
commit 82174afdea
23 changed files with 114 additions and 1000 deletions
+26 -9
View File
@@ -2,6 +2,7 @@
namespace Lucent\Schema;
use Lucent\LucentException;
use Lucent\Primitive\Collection;
class SchemaService
@@ -52,16 +53,32 @@ class SchemaService
public function mapFields(array $field): FieldInterface
{
$className = "\\Lucent\Schema\Ui\\" . ucfirst($field["ui"]);
unset($field["ui"]);
return new $className(...$field);
$schemaFields = [
\Lucent\Schema\Ui\Checkbox::class,
\Lucent\Schema\Ui\Color::class,
\Lucent\Schema\Ui\Date::class,
\Lucent\Schema\Ui\Datetime::class,
\Lucent\Schema\Ui\File::class,
\Lucent\Schema\Ui\Json::class,
\Lucent\Schema\Ui\Markdown::class,
\Lucent\Schema\Ui\Number::class,
\Lucent\Schema\Ui\Reference::class,
\Lucent\Schema\Ui\Rich::class,
\Lucent\Schema\Ui\Slug::class,
\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();
if (empty($ui)) {
throw new LucentException("Field UI " . $field["ui"] . " not found");
}
unset($field["ui"]);
return new $ui(...$field);
}
public function mapBlockFields(array $field): FieldInterface
{
$className = "\\Lucent\Schema\BlockUi\\" . ucfirst($field["ui"]);
unset($field["ui"]);
return new $className(...$field);
}
}