<?php
namespace App\Controller;
use App\Service\ShortCodeService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class FrontController extends AbstractController
{
/**
* @Route("/{short_code}", name="app_front_index")
*
* @param ShortCodeService $shortCodeService
* @param $short_code
* @return Response
*/
public function index(ShortCodeService $shortCodeService, $short_code): Response
{
$redirect_to_url = $shortCodeService->getShortCode($short_code);
if(!is_null($redirect_to_url)) {
$shortCodeService->addShortCodeVisit($short_code);
return $this->redirect($redirect_to_url);
}
return $this->render('http/404.html.twig', [
'controller_name' => 'HttpController',
]);
}
}