src/Component/Captcha/Form/CaptchaType.php line 15

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Component\Captcha\Form;
  4. use App\Component\Captcha\CaptchaFactory;
  5. use App\Component\Captcha\CaptchaInterface;
  6. use App\Component\Captcha\EventSubscriber\CaptchaEventSubscriber;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Contracts\Translation\TranslatorInterface;
  11. class CaptchaType extends AbstractType
  12. {
  13.     private readonly CaptchaInterface $captcha;
  14.     public function __construct(
  15.         private readonly CaptchaFactory $factory,
  16.         private readonly TranslatorInterface $translator,
  17.     ) {
  18.         $this->captcha $this->factory->create();
  19.     }
  20.     public function buildForm(FormBuilderInterface $builder, array $options): void
  21.     {
  22.         $builder->addEventSubscriber(new CaptchaEventSubscriber($this->factory$this->translator));
  23.     }
  24.     public function configureOptions(OptionsResolver $resolver): void
  25.     {
  26.         $resolver->setDefaults([
  27.             'mapped' => false,
  28.         ]);
  29.     }
  30.     public function getBlockPrefix(): string
  31.     {
  32.         return $this->captcha::getBlockPrefix();
  33.     }
  34. }