SessionFactory.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 ?\Closure $usageReporter;
  21. public function __construct(
  22. private RequestStack $requestStack,
  23. private SessionStorageFactoryInterface $storageFactory,
  24. ?callable $usageReporter = null,
  25. ) {
  26. $this->usageReporter = null === $usageReporter ? null : $usageReporter(...);
  27. }
  28. public function createSession(): SessionInterface
  29. {
  30. return new Session($this->storageFactory->createStorage($this->requestStack->getMainRequest()), null, null, $this->usageReporter);
  31. }
  32. }