PhpBridgeSessionStorageFactory.php 1.2 KB

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