Files
lucent-laravel/src/Commands/CompileSchemas.php
T

46 lines
1.1 KiB
PHP
Raw Normal View History

2023-10-06 13:07:09 +03:00
<?php
namespace Lucent\Commands;
use DirectoryIterator;
use Illuminate\Console\Command;
2023-10-17 22:57:25 +03:00
use Lucent\Schema\Schema;
use Lucent\Schema\SchemaService;
use Lucent\Schema\Type;
2026-01-07 21:42:18 +02:00
use Yosymfony\Toml\Toml;
2023-10-06 13:07:09 +03:00
class CompileSchemas extends Command
{
2026-01-07 21:42:18 +02:00
protected $signature = "lucent:schemas";
2023-10-06 13:07:09 +03:00
2026-01-07 21:42:18 +02:00
protected $description = "Compiles schemas";
2023-10-06 13:07:09 +03:00
2024-08-27 12:24:51 +03:00
public function handle(SchemaService $schemaService)
2023-10-06 13:07:09 +03:00
{
2026-01-07 21:42:18 +02:00
$configDir = base_path(config("lucent.schemas_path"));
2023-10-06 13:07:09 +03:00
$schemasDirIterator = new DirectoryIterator($configDir);
$schemas = [];
2024-08-27 12:24:51 +03:00
2023-10-06 13:07:09 +03:00
foreach ($schemasDirIterator as $file) {
2026-01-07 21:42:18 +02:00
if ($file->getExtension() !== "toml") {
2023-10-06 13:07:09 +03:00
continue;
}
2026-01-07 21:42:18 +02:00
$schemaData = Toml::ParseFile(
$configDir . "/" . $file->getFilename(),
);
2023-10-06 13:07:09 +03:00
2026-01-07 21:42:18 +02:00
$schemas[] = $schemaData;
2023-10-06 13:07:09 +03:00
}
2023-10-17 22:57:25 +03:00
$schemas = collect($schemas)->sortBy("label")->values();
if (!file_exists(storage_path("lucent"))) {
2023-10-06 13:07:09 +03:00
mkdir(storage_path("lucent"));
}
2026-01-07 21:42:18 +02:00
file_put_contents(schemas_path(), json_encode($schemas));
2023-10-06 13:07:09 +03:00
$this->info("Lucent Schemas were updated");
}
}