src/Controller/Front/OptionsController.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use Throwable;
  4. use App\Service\ClientService;
  5. use App\Utils\Utils;
  6. use Psr\Log\LoggerInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. class OptionsController extends AbstractController
  13. {
  14.     /**
  15.      * @Route("/options", name="default_options", methods={"GET"}, priority="1", options={"expose" = true})
  16.      */
  17.     public function options(Request $requestClientService $clientServiceLoggerInterface $logger): JsonResponse
  18.     {
  19.         try {
  20.             $listOptions $request->get('option');
  21.             $options $clientService->getOptions();
  22.             $options['codePhones'] = Utils::codePhones();
  23.             $temp = [];
  24.             foreach ($listOptions as $option) {
  25.                 foreach ($options[$option] as $value) {
  26.                     $temp[$option][$value] = $value;
  27.                 }
  28.             }
  29.             $options $temp;
  30.         } catch (Throwable $exception) {
  31.             $logger->error($exception->getMessage());
  32.             return $this->json([
  33.                 'error' => true,
  34.             ], Response::HTTP_INTERNAL_SERVER_ERROR);
  35.         }
  36.         return $this->json($options);
  37.     }
  38. }