NativeSessionStorageFactory.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. // Help opcache.preload discover always-needed symbols
  13. class_exists(NativeSessionStorage::class);
  14. /**
  15. * @author Jérémy Derussé <jeremy@derusse.com>
  16. */
  17. class NativeSessionStorageFactory implements SessionStorageFactoryInterface
  18. {
  19. private $options;
  20. private $handler;
  21. private $metaBag;
  22. private $secure;
  23. /**
  24. * @see NativeSessionStorage constructor.
  25. */
  26. public function __construct(array $options = [], $handler = null, MetadataBag $metaBag = null, bool $secure = false)
  27. {
  28. $this->options = $options;
  29. $this->handler = $handler;
  30. $this->metaBag = $metaBag;
  31. $this->secure = $secure;
  32. }
  33. public function createStorage(?Request $request): SessionStorageInterface
  34. {
  35. $storage = new NativeSessionStorage($this->options, $this->handler, $this->metaBag);
  36. if ($this->secure && $request && $request->isSecure()) {
  37. $storage->setOptions(['cookie_secure' => true]);
  38. }
  39. return $storage;
  40. }
  41. }