vendor/symfony/http-kernel/EventListener/SessionListener.php line 50

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\HttpKernel\EventListener;
  11. use Psr\Container\ContainerInterface;
  12. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  13. use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
  14. /**
  15.  * Sets the session in the request.
  16.  *
  17.  * When the passed container contains a "session_storage" entry which
  18.  * holds a NativeSessionStorage instance, the "cookie_secure" option
  19.  * will be set to true whenever the current master request is secure.
  20.  *
  21.  * @author Fabien Potencier <fabien@symfony.com>
  22.  *
  23.  * @final
  24.  */
  25. class SessionListener extends AbstractSessionListener
  26. {
  27.     public function __construct(ContainerInterface $containerbool $debug false)
  28.     {
  29.         parent::__construct($container$debug);
  30.     }
  31.     protected function getSession(): ?SessionInterface
  32.     {
  33.         if (!$this->container->has('session')) {
  34.             return null;
  35.         }
  36.         if ($this->container->has('session_storage')
  37.             && ($storage $this->container->get('session_storage')) instanceof NativeSessionStorage
  38.             && ($masterRequest $this->container->get('request_stack')->getMasterRequest())
  39.             && $masterRequest->isSecure()
  40.         ) {
  41.             $storage->setOptions(['cookie_secure' => true]);
  42.         }
  43.         return $this->container->get('session');
  44.     }
  45. }