src/Controller/HomeController.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Form\MailerFormType;
  4. use App\Service\CaptchaService;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class HomeController extends AbstractController
  9. {
  10.     public function __construct(
  11.         private CaptchaService $captchaService,
  12.     )
  13.     {}
  14.     #[Route('/'name'home_page')]
  15.     public function page(): Response
  16.     {
  17.         $form $this->createForm(MailerFormType::class);
  18.         return $this->render('home/index.html.twig', [
  19.             'mailerForm' => $form->createView()
  20.         ]);
  21.     }
  22.     #[Route('/captcha/image'name'captcha_image')]
  23.     public function image()
  24.     {
  25.         define('USE_SESSION'true);
  26.         $code $this->captchaService->codeGenerator();
  27.         $rootPath $this->getParameter('kernel.project_dir');
  28.         $imagePath $rootPath '/public/assets/doapp/captcha/bg.png';
  29.         $fontPath $rootPath '/public/assets/doapp/captcha/oswald.ttf';
  30.         $this->captchaService->backgroundGenerator($imagePath$fontPath$code);
  31.     }
  32.     #[Route('/captcha/handler'name'captcha_handler')]
  33.     public function handler(): Response
  34.     {
  35.         $result $this->captchaService->captchaHandler();
  36.         return new Response(json_encode($result));
  37.     }
  38. }