Skip to content

Instantly share code, notes, and snippets.

@tarlepp
Created March 21, 2021 13:15
Show Gist options
  • Save tarlepp/25f30aaefd7a499586f0bd852aa7725d to your computer and use it in GitHub Desktop.
Save tarlepp/25f30aaefd7a499586f0bd852aa7725d to your computer and use it in GitHub Desktop.
<?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