ldc-showroom-bo/app/Lib/Helpers/ToolboxHelper.php
2025-05-28 17:20:29 +02:00

37 lines
1.2 KiB
PHP

<?php
namespace App\Lib\Helpers;
use Illuminate\Support\Str;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\File;
use Uwil\LaravelCommon\Helpers\ToolboxHelper as CommonToolboxHelper;
class ToolboxHelper extends CommonToolboxHelper
{
/**
* Get a specific json schema
*
* @param string $schema
* @return array|false Returns false if the schema cannot be found.
* @throws \RuntimeException If the schema does not exists.
*/
public static function getJsonSchema(string $schema): array|false
{
$schemaPath = Str::of(config('json-schema.local_base_prefix'))->finish("/{$schema}");
if (!File::exists($schemaPath)) {
return false;
}
$schemaContent = File::get($schemaPath);
if (!Str::isJson($schemaContent)) {
throw new \RuntimeException("{$schemaPath} is not a json schema .");
}
$schemaContent = json_decode($schemaContent, true);
$schemaRoute = route('fo.schema', ['schema' => $schema]);
if (app()->environment('local')) {
$schemaRoute = Str::replace('https', 'http', $schemaRoute);
}
Arr::set($schemaContent, '$id', $schemaRoute);
return $schemaContent;
}
}