Created
March 21, 2021 13:15
-
-
Save tarlepp/25f30aaefd7a499586f0bd852aa7725d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\EventSubscriber; | |
use App\Entity\User; | |
use Symfony\Component\HttpKernel\Event\RequestEvent; | |
use Symfony\Component\Routing\Router; | |
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | |
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | |
class Foo | |
{ | |
public function __construct( | |
private Router $router, | |
private TokenStorageInterface $tokenStorage | |
) { | |
} | |
public function onKernelRequest(RequestEvent $event): void | |
{ | |
$token = $this->tokenStorage->getToken(); | |
if ($token instanceof TokenInterface) { | |
$user = $token->getUser(); | |
if ($user instanceof User && $user->getCompanyProfile() === null) { | |
$this->router->generate('selected_account_type'); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment