Added backends/spec API endpoint.

This commit is contained in:
Abdulmhsen B. A. A
2024-05-18 17:49:55 +03:00
parent efcfc73652
commit 696bba21b9

40
src/API/Backends/Spec.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace App\API\Backends;
use App\Libs\Attributes\Route\Get;
use App\Libs\HTTP_STATUS;
use App\Libs\Traits\APITraits;
use Psr\Http\Message\ResponseInterface as iResponse;
use Psr\Http\Message\ServerRequestInterface as iRequest;
final class Spec
{
use APITraits;
#[Get(Index::URL . '/spec[/]', name: 'backends.spec')]
public function __invoke(iRequest $request, array $args = []): iResponse
{
$specs = require __DIR__ . '/../../../config/servers.spec.php';
$list = [];
foreach ($specs as $spec) {
$item = [
'key' => $spec['key'],
'type' => $spec['type'],
'description' => $spec['description'],
];
if (ag_exists($spec, 'choices')) {
$item['choices'] = $spec['choices'];
}
$list[] = $item;
}
return api_response(HTTP_STATUS::HTTP_OK, $list);
}
}