PhpBridgeSessionStorageFactory.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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(PhpBridgeSessionStorage::class);
  15. /**
  16. * @author Jérémy Derussé <jeremy@derusse.com>
  17. */
  18. class PhpBridgeSessionStorageFactory implements SessionStorageFactoryInterface
  19. {
  20. public function __construct(
  21. private AbstractProxy|\SessionHandlerInterface|null $handler = null,
  22. private ?MetadataBag $metaBag = null,
  23. private bool $secure = false,
  24. ) {
  25. }
  26. public function createStorage(?Request $request): SessionStorageInterface
  27. {
  28. $storage = new PhpBridgeSessionStorage($this->handler, $this->metaBag);
  29. if ($this->secure && $request?->isSecure()) {
  30. $storage->setOptions(['cookie_secure' => true]);
  31. }
  32. return $storage;
  33. }
  34. }