src/Controller/MainController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\Validator\Constraints\Date;
  7. class MainController extends AbstractController
  8. {
  9.     /**
  10.      * @Route("/", name="index")
  11.      */
  12.     public function index(): Response
  13.     {
  14.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  15.         return $this->render('index.html.twig', [
  16.         ]);
  17.     }
  18. //
  19. //    /**
  20. //     * @Route("/administration", name="admin")
  21. //     */
  22. //    public function admin(): Response
  23. //    {
  24. //        return $this->render('url/index.html.twig', [
  25. //            'controller_name' => 'MainController',
  26. //        ]);
  27. //    }
  28.     /**
  29.      * @Route("/{urlShortcut}", name="urlRedirect", requirements={"urlShortcut"="[a-z,A-Z,0-9]{4,4}"})
  30.      *
  31.      *
  32.      */
  33.     public function urlredirect($urlShortcut): Response
  34.     {
  35.         $em $this->getDoctrine()->getManager();
  36.         $shortcut $em->getRepository("App:UrlShortener")->findBy(['shortcut'=> $urlShortcut]);
  37.         if ($shortcut != null){
  38.             if (sizeof($shortcut) == 1){
  39.                 $date = new \DateTime();
  40.                 $shortcut[0]->setLastUsed($date);
  41.                 $shortcut[0]->setNbUsed($shortcut[0]->getNbUsed() + 1);
  42.                 $em->persist($shortcut[0]);
  43.                 $em->flush();
  44.                 return $this->redirect($shortcut[0]->getUrl());
  45.             }
  46.         }
  47.         return $this->render('url/404.html.twig');
  48.     }
  49.     /**
  50.      * @Route("/link/{urlShortcut}", name="long_urlRedirect")
  51.      *
  52.      *
  53.      */
  54.     public function urlredirect_long($urlShortcut): Response
  55.     {
  56.         $urlShortcut "link/".$urlShortcut;
  57.         $em $this->getDoctrine()->getManager();
  58.         $shortcut $em->getRepository("App:UrlShortener")->findBy(['shortcut'=> $urlShortcut]);
  59.         if ($shortcut != null){
  60.             if (sizeof($shortcut) == 1){
  61.                 $date = new \DateTime();
  62.                 $shortcut[0]->setLastUsed($date);
  63.                 $shortcut[0]->setNbUsed($shortcut[0]->getNbUsed() + 1);
  64.                 $em->persist($shortcut[0]);
  65.                 $em->flush();
  66.                 return $this->redirect($shortcut[0]->getUrl());
  67.             }
  68.         }
  69.         return $this->render('url/404.html.twig');
  70.     }
  71. }