SessionFactory.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageFactoryInterface;
  13. // Help opcache.preload discover always-needed symbols
  14. class_exists(Session::class);
  15. /**
  16. * @author Jérémy Derussé <jeremy@derusse.com>
  17. */
  18. class SessionFactory implements SessionFactoryInterface
  19. {
  20. private $requestStack;
  21. private $storageFactory;
  22. private $usageReporter;
  23. public function __construct(RequestStack $requestStack, SessionStorageFactoryInterface $storageFactory, ?callable $usageReporter = null)
  24. {
  25. $this->requestStack = $requestStack;
  26. $this->storageFactory = $storageFactory;
  27. $this->usageReporter = $usageReporter;
  28. }
  29. public function createSession(): SessionInterface
  30. {
  31. return new Session($this->storageFactory->createStorage($this->requestStack->getMainRequest()), null, null, $this->usageReporter);
  32. }
  33. }