2024-01-05 11:28:16 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Lib\Helpers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
|
use Illuminate\Support\Facades\File;
|
2025-05-28 17:20:29 +02:00
|
|
|
use Uwil\LaravelCommon\Helpers\ToolboxHelper as CommonToolboxHelper;
|
2024-01-05 11:28:16 +01:00
|
|
|
|
2025-05-28 17:20:29 +02:00
|
|
|
class ToolboxHelper extends CommonToolboxHelper
|
2024-01-05 11:28:16 +01:00
|
|
|
{
|
2024-01-08 15:28:00 +01:00
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
{
|
2025-05-14 17:17:44 +02:00
|
|
|
$schemaPath = Str::of(config('json-schema.local_base_prefix'))->finish("/{$schema}");
|
2024-01-08 15:28:00 +01:00
|
|
|
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);
|
2024-10-08 08:27:56 +02:00
|
|
|
$schemaRoute = route('fo.schema', ['schema' => $schema]);
|
|
|
|
|
if (app()->environment('local')) {
|
|
|
|
|
$schemaRoute = Str::replace('https', 'http', $schemaRoute);
|
|
|
|
|
}
|
|
|
|
|
Arr::set($schemaContent, '$id', $schemaRoute);
|
2024-01-08 15:28:00 +01:00
|
|
|
return $schemaContent;
|
|
|
|
|
}
|
2024-01-05 11:28:16 +01:00
|
|
|
}
|