<?php
namespace App\Controller\Front;
use Throwable;
use App\Service\ClientService;
use App\Utils\Utils;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class OptionsController extends AbstractController
{
/**
* @Route("/options", name="default_options", methods={"GET"}, priority="1", options={"expose" = true})
*/
public function options(Request $request, ClientService $clientService, LoggerInterface $logger): JsonResponse
{
try {
$listOptions = $request->get('option');
$options = $clientService->getOptions();
$options['codePhones'] = Utils::codePhones();
$temp = [];
foreach ($listOptions as $option) {
foreach ($options[$option] as $value) {
$temp[$option][$value] = $value;
}
}
$options = $temp;
} catch (Throwable $exception) {
$logger->error($exception->getMessage());
return $this->json([
'error' => true,
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
return $this->json($options);
}
}