<?php
declare(strict_types=1);
namespace App\Security;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
class AuthenticationEntryPoint implements AuthenticationEntryPointInterface
{
private $urlGenerator;
public function __construct(UrlGeneratorInterface $urlGenerator)
{
$this->urlGenerator = $urlGenerator;
}
public function start(Request $request, AuthenticationException $authException = null): RedirectResponse
{
$request->getSession()->getFlashBag()->add('danger', 'Musisz się zalogować, aby uzyskać dostęp do tej strony.');
return new RedirectResponse($this->urlGenerator->generate('app_login'));
}
}