vendor/symfony/security/Http/Firewall/ChannelListener.php line 25

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <[email protected]>
  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 Psr\Log\LoggerInterface;
  12. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  13. use Symfony\Component\Security\Http\AccessMapInterface;
  14. use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
  15. /**
  16.  * ChannelListener switches the HTTP protocol based on the access control
  17.  * configuration.
  18.  *
  19.  * @author Fabien Potencier <[email protected]>
  20.  */
  21. class ChannelListener implements ListenerInterface
  22. {
  23.     private $map;
  24.     private $authenticationEntryPoint;
  25.     private $logger;
  26.     public function __construct(AccessMapInterface $mapAuthenticationEntryPointInterface $authenticationEntryPointLoggerInterface $logger null)
  27.     {
  28.         $this->map $map;
  29.         $this->authenticationEntryPoint $authenticationEntryPoint;
  30.         $this->logger $logger;
  31.     }
  32.     /**
  33.      * Handles channel management.
  34.      */
  35.     public function handle(GetResponseEvent $event)
  36.     {
  37.         $request $event->getRequest();
  38.         list(, $channel) = $this->map->getPatterns($request);
  39.         if ('https' === $channel && !$request->isSecure()) {
  40.             if (null !== $this->logger) {
  41.                 $this->logger->info('Redirecting to HTTPS.');
  42.             }
  43.             $response $this->authenticationEntryPoint->start($request);
  44.             $event->setResponse($response);
  45.             return;
  46.         }
  47.         if ('http' === $channel && $request->isSecure()) {
  48.             if (null !== $this->logger) {
  49.                 $this->logger->info('Redirecting to HTTP.');
  50.             }
  51.             $response $this->authenticationEntryPoint->start($request);
  52.             $event->setResponse($response);
  53.         }
  54.     }
  55. }