NativeSessionStorageFactory.php 1.3 KB

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