<?php
namespace App\Controller;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class DefaultController extends AbstractController
{
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
/**
* @Route("/", name="default")
*/
public function index(): Response
{
$user = $this->security->getUser();
if (!$user) {
return $this->redirectToRoute("app_login");
}
$roles = $user->getRoles();
foreach (['admin', 'business', 'staff', 'customer'] as $role)
if (in_array('ROLE_' . strtoupper($role), $roles)) {
return $this->redirectToRoute($role);
}
}
}