vendor/symfony/security-http/Firewall/AbstractListener.php line 24

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Security\Http\Firewall;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpKernel\Event\RequestEvent;
  13. /**
  14.  * A base class for listeners that can tell whether they should authenticate incoming requests.
  15.  *
  16.  * @author Nicolas Grekas <p@tchwork.com>
  17.  */
  18. abstract class AbstractListener
  19. {
  20.     final public function __invoke(RequestEvent $event)
  21.     {
  22.         if (false !== $this->supports($event->getRequest())) {
  23.             $this->authenticate($event);
  24.         }
  25.     }
  26.     /**
  27.      * Tells whether the authenticate() method should be called or not depending on the incoming request.
  28.      *
  29.      * Returning null means authenticate() can be called lazily when accessing the token storage.
  30.      */
  31.     abstract public function supports(Request $request): ?bool;
  32.     /**
  33.      * Does whatever is required to authenticate the request, typically calling $event->setResponse() internally.
  34.      */
  35.     abstract public function authenticate(RequestEvent $event);
  36. }