vendor/symfony/framework-bundle/Session/DeprecatedSessionFactory.php line 41

Open in your IDE?
  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\Bundle\FrameworkBundle\Session;
  11. use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException;
  12. use Symfony\Component\HttpFoundation\RequestStack;
  13. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  14. /**
  15. * Provides session and trigger deprecation.
  16. *
  17. * Used by service that should trigger deprecation when accessed by the user.
  18. *
  19. * @author Jérémy Derussé <jeremy@derusse.com>
  20. *
  21. * @internal to be removed in 6.0
  22. */
  23. class DeprecatedSessionFactory
  24. {
  25. private $requestStack;
  26. public function __construct(RequestStack $requestStack)
  27. {
  28. $this->requestStack = $requestStack;
  29. }
  30. public function getSession(): ?SessionInterface
  31. {
  32. trigger_deprecation('symfony/framework-bundle', '5.3', 'The "session" service and "SessionInterface" alias are deprecated, use "$requestStack->getSession()" instead.');
  33. try {
  34. return $this->requestStack->getSession();
  35. } catch (SessionNotFoundException $e) {
  36. return null;
  37. }
  38. }
  39. }