<?php
declare(strict_types = 1);
namespace App\Action;
use App\Domain\Repository\Interfaces\TextRepositoryInterface;
use App\Form\Handler\ContactFormHandler;
use App\Form\Type\ContactFormType;
use App\Responder\RedirectResponder;
use App\Responder\TemplateResponder;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class ContactAction extends AbstractAction
{
public function __construct(
TemplateResponder $templateResponder,
RedirectResponder $redirectResponder,
FormFactoryInterface $formFactory,
ContactFormHandler $contactFormHandler
)
{
$this->templateResponder = $templateResponder;
$this->redirectResponder = $redirectResponder;
$this->formFactory = $formFactory;
$this->contactFormHandler = $contactFormHandler;
}
/**
* @Route("/contact", name="contact")
*/
public function __invoke(Request $request)
{
$contactType = $this->formFactory
->create(ContactFormType::class)
->handleRequest($request);
if ($this->contactFormHandler->handle($contactType)) {
return $this->redirectResponder->__invoke('contact');
}
return $this->templateResponder->__invoke(
'contact.html.twig', [
'form' => $contactType->createView()
]
);
}
}