src/Controller/DefaultController.php line 51

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\Controller;
  3. use App\Entity\Order;
  4. use App\Form\OrderFormType;
  5. use App\Service\OrderService;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\RedirectResponse as RedirectResponse;
  9. use Symfony\Component\HttpFoundation\RequestStack;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. /**
  13.  * Class DefaultController
  14.  * @package App\Controller
  15.  */
  16. class DefaultController extends AbstractController
  17. {
  18.     /**
  19.      * @var RequestStack
  20.      */
  21.     private $request;
  22.     /**
  23.      * @var OrderService
  24.      */
  25.     private $orderService;
  26.     /**
  27.      * DefaultController constructor.
  28.      *
  29.      * @param RequestStack $request
  30.      * @param OrderService $orderService
  31.      */
  32.     public function __construct(
  33.         RequestStack $request,
  34.         OrderService $orderService
  35.     ) {
  36.         $this->request $request->getCurrentRequest();
  37.         $this->orderService $orderService;
  38.     }
  39.     /**
  40.      * @Route("/", name="index")
  41.      * @Template()
  42.      *
  43.      * @return array|RedirectResponse
  44.      */
  45.     public function index()
  46.     {
  47.         $addOrder $this->orderService->doDisplayOrder();
  48.         $response = [];
  49.         if ($addOrder) {
  50.             $order = new Order();
  51.             $form $this->createForm(OrderFormType::class, $order, ['submit' => true]);
  52.             $form->handleRequest($this->request);
  53.             $response['form'] = $form->createView();
  54.             if ($form->isSubmitted() && $form->isValid()) {
  55.                 return $this->redirectToRoute('dashboard');
  56.             }
  57.         }
  58.         return $response;
  59.     }
  60.     /**
  61.      * @Route("privacy-statement", name="privacy_statement")
  62.      */
  63.     public function privacyStatement(): Response
  64.     {
  65.         return $this->render('security/privacy-statement.html.twig');
  66.     }
  67.     /**
  68.      * @Route("cgu", name="cgu")
  69.      */
  70.     public function cgu(): Response
  71.     {
  72.         return $this->render('security/cgufront.html.twig');
  73.     }
  74. }