src/Controller/Api/DataTypesController.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\Entity\Vacancy;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Serializer\Exception\ExceptionInterface;
  8. use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
  9. class DataTypesController extends AbstractController
  10. {
  11.     protected NormalizerInterface $normalizer;
  12.     /**
  13.      * EducationSearchController constructor.
  14.      */
  15.     public function __construct(NormalizerInterface $normalizer)
  16.     {
  17.         $this->normalizer $normalizer;
  18.     }
  19.     /**
  20.      * @throws ExceptionInterface
  21.      * @throws \JsonException
  22.      */
  23.     #[Route(path'/classes.js'name'fetch_datatype_classes_js')]
  24.     public function index(): Response
  25.     {
  26.         $vacancyMap = (new Vacancy())
  27.             ->setTitle('')
  28.         ;
  29.         $dataMap = [
  30.             'vacancy' => $this->normalizer->normalize($vacancyMap),
  31.         ];
  32.         $response = new Response();
  33.         $response->headers->set('Content-Type''application/javascript');
  34.         return $this->render('api/datatypes.js.twig', [
  35.             'datamap' => json_encode($dataMap\JSON_THROW_ON_ERROR),
  36.         ], $response);
  37.     }
  38. }