diff --git a/src/Controller/IndexController.php b/src/Controller/IndexController.php index 0e8fbf0..f17cfd1 100644 --- a/src/Controller/IndexController.php +++ b/src/Controller/IndexController.php @@ -2,16 +2,37 @@ namespace App\Controller; +use App\Entity\QRCode\QRCode; +use App\Form\Type\QRCodeType; +use App\Service\QRCodeQROptionsProviderInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; class IndexController extends AbstractController { #[Route('/', name: 'homepage')] - public function indexAction(): Response + public function indexAction(Request $request, QRCodeQROptionsProviderInterface $qrCodeQROptionsFactory): Response { - $result = $this->render('index/homepage.html.twig'); - return $result; + $qrCode = new QRCode( + codeQROptions: $qrCodeQROptionsFactory->getDefault() + ); + + $form = $this->createForm(QRCodeType::class, $qrCode); + + + if ($request->isMethod('POST')) { + $form->submit($request->request->all($form->getName())); + + if ($form->isSubmitted() && $form->isValid()) { + // TODO: call service to generate + print_r($qrCode); + } + } + + return $this->render('index/homepage.html.twig', [ + 'form' => $form + ]); } -} \ No newline at end of file +} diff --git a/src/Service/QRCodeQROptionsDefaultProvider.php b/src/Service/QRCodeQROptionsDefaultProvider.php index 653a571..7ae853d 100644 --- a/src/Service/QRCodeQROptionsDefaultProvider.php +++ b/src/Service/QRCodeQROptionsDefaultProvider.php @@ -5,8 +5,8 @@ namespace App\Service; use App\Entity\QRCode\QRCodeQROptions; -readonly class QRCodeQROptionsDefaultProvider implements QRCodeQROptionsProviderInterface { - private readonly QRCodeQROptions $qrCodeDefaultOptions; +readonly final class QRCodeQROptionsDefaultProvider implements QRCodeQROptionsProviderInterface { + private QRCodeQROptions $qrCodeDefaultOptions; public function __construct() { $this->qrCodeDefaultOptions = new QRCodeQROptions( diff --git a/templates/index/homepage.html.twig b/templates/index/homepage.html.twig index 22b6e74..dccff10 100644 --- a/templates/index/homepage.html.twig +++ b/templates/index/homepage.html.twig @@ -2,4 +2,5 @@ {% block body %} Homepage -{% endblock %} \ No newline at end of file +{{ form(form) }} +{% endblock %}