<?php
declare(strict_types=1);
namespace App\Component\Captcha\Form;
use App\Component\Captcha\CaptchaFactory;
use App\Component\Captcha\CaptchaInterface;
use App\Component\Captcha\EventSubscriber\CaptchaEventSubscriber;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
class CaptchaType extends AbstractType
{
private readonly CaptchaInterface $captcha;
public function __construct(
private readonly CaptchaFactory $factory,
private readonly TranslatorInterface $translator,
) {
$this->captcha = $this->factory->create();
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->addEventSubscriber(new CaptchaEventSubscriber($this->factory, $this->translator));
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'mapped' => false,
]);
}
public function getBlockPrefix(): string
{
return $this->captcha::getBlockPrefix();
}
}