Files
SomniaRooms/src/Controller/ConfigVariableController.php
T
Daniel-Garmig 734a4a8fee Updated dependencies (mayor)
- nelmio/api-doc-bundle 4.x to 5.6
- phpstan/phpdoc-parser 1.x to 2.x
- Fixed deprecations.
2025-10-21 22:31:56 +02:00

129 lines
3.9 KiB
PHP

<?php
namespace App\Controller;
use App\ApiErrorException;
use App\DTO\ApiErrorMessage;
use App\Entity\ConfigVariable;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use App\Repository\ConfigVariableRepository;
use Nelmio\ApiDocBundle\Attribute\Model;
use OpenApi\Attributes as OA;
class ConfigVariableController extends AbstractController
{
/**
* Get All config variables.
*/
#[Route('/api/config', name: 'app_config_allVariable', methods: ["GET"])]
#[OA\Tag(name: "Config")]
#[OA\Response(
response: 200,
description: 'Returns all public config variables.',
content: new OA\JsonContent(
type: 'object',
properties: [
new OA\Property(
property: "results",
type: "array",
items: new OA\Items(ref: new Model(type: ConfigVariable::class))
)
]
)
)]
public function getAllVariables(ConfigVariableRepository $repo): Response
{
$varList = $repo->findAllVariables();
return $this->json(['results' => $varList]);
}
#[Route('/api/config/section', name: 'app_config_sections', methods: ["GET"])]
#[OA\Tag(name: "Config")]
#[OA\Response(
response: 200,
description: 'Returns all public config sections.',
content: new OA\JsonContent(
type: 'object',
properties: [
new OA\Property(
property: "results",
type: "array",
items: new OA\Items(type: "string")
)
]
)
)]
public function getSections(ConfigVariableRepository $repo): Response
{
$sectionList = $repo->getAllSections();
$returnList = [];
foreach ($sectionList as $section) {
$sectionValue = $section["section"];
$returnList[] = $sectionValue;
}
return $this->json(['results' => $returnList]);
}
#[Route('/api/config/section/{section}', name: 'app_config_variableBySection', methods: ["GET"])]
#[OA\Tag(name: "Config")]
#[OA\Response(
response: 200,
description: 'Returns all public config variables for given section.',
content: new OA\JsonContent(
type: 'object',
properties: [
new OA\Property(
property: "results",
type: "array",
items: new OA\Items(ref: new Model(type: ConfigVariable::class))
)
]
)
)]
#[OA\Parameter(
name: 'section',
in: 'path',
description: 'Config section.',
schema: new OA\Schema(type: 'string')
)]
public function getVariablesBySection(ConfigVariableRepository $repo, string $section): Response
{
if(\is_null($section) || $section == '') {
throw new ApiErrorException(
new ApiErrorMessage(400, ApiErrorMessage::TYPE_INVALID_REQUEST_BODY_FORMAT)
);
}
$varList = $repo->findAllBySection($section);
return $this->json(['results' => $varList]);
}
#[Route('/api/config/var/{key}', name: 'app_config_variable', methods: ["GET"])]
#[OA\Tag(name: "Config")]
#[OA\Response(
response: 200,
description: 'Get config variable by key.',
content: new OA\JsonContent(
type: 'object',
ref: new Model(type: ConfigVariable::class),
)
)]
#[OA\Parameter(
name: 'key',
in: 'path',
description: 'Variable key.',
schema: new OA\Schema(type: 'string')
)]
public function getByKey(ConfigVariableRepository $repo, string $key): Response
{
$var = $repo->findVariableByKey($key);
return $this->json($var);
}
}