ServiceSessionFactory.php 961 B

1234567891011121314151617181920212223242526272829303132333435363738
  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\HttpFoundation\Session\Storage;
  11. use Symfony\Component\HttpFoundation\Request;
  12. /**
  13. * @author Jérémy Derussé <jeremy@derusse.com>
  14. *
  15. * @internal to be removed in Symfony 6
  16. */
  17. final class ServiceSessionFactory implements SessionStorageFactoryInterface
  18. {
  19. private $storage;
  20. public function __construct(SessionStorageInterface $storage)
  21. {
  22. $this->storage = $storage;
  23. }
  24. public function createStorage(?Request $request): SessionStorageInterface
  25. {
  26. if ($this->storage instanceof NativeSessionStorage && $request && $request->isSecure()) {
  27. $this->storage->setOptions(['cookie_secure' => true]);
  28. }
  29. return $this->storage;
  30. }
  31. }