vendor/se7enxweb/legacy-bridge/bundle/LegacyMapper/Session.php line 38

Open in your IDE?
  1. <?php
  2. /**
  3. * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  4. * @license For full copyright and license information view LICENSE file distributed with this source code.
  5. */
  6. namespace eZ\Bundle\EzPublishLegacyBundle\LegacyMapper;
  7. use eZ\Publish\Core\MVC\Legacy\Event\PreBuildKernelEvent;
  8. use eZ\Publish\Core\MVC\Legacy\LegacyEvents;
  9. use eZ\Publish\Core\MVC\Symfony\RequestStackAware;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  12. use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
  13. /**
  14. * Maps the session parameters to the legacy parameters.
  15. */
  16. class Session implements EventSubscriberInterface
  17. {
  18. use RequestStackAware;
  19. /**
  20. * @var \Symfony\Component\HttpFoundation\Session\SessionInterface
  21. */
  22. private $session;
  23. /**
  24. * @var \Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface
  25. */
  26. private $sessionStorage;
  27. /**
  28. * @var string
  29. */
  30. private $sessionStorageKey;
  31. public function __construct(SessionStorageInterface $sessionStorage, $sessionStorageKey, SessionInterface $session = null)
  32. {
  33. $this->sessionStorage = $sessionStorage;
  34. $this->sessionStorageKey = $sessionStorageKey;
  35. $this->session = $session;
  36. }
  37. public static function getSubscribedEvents()
  38. {
  39. return [
  40. LegacyEvents::PRE_BUILD_LEGACY_KERNEL => ['onBuildKernelHandler', 128],
  41. ];
  42. }
  43. /**
  44. * Adds the session settings to the parameters that will be injected
  45. * into the legacy kernel.
  46. *
  47. * @param \eZ\Publish\Core\MVC\Legacy\Event\PreBuildKernelEvent $event
  48. */
  49. public function onBuildKernelHandler(PreBuildKernelEvent $event)
  50. {
  51. $sessionInfos = [
  52. 'configured' => false,
  53. 'started' => false,
  54. 'name' => false,
  55. 'namespace' => false,
  56. 'has_previous' => false,
  57. 'storage' => false,
  58. ];
  59. if (isset($this->session)) {
  60. $request = $this->getCurrentRequest();
  61. $sessionInfos['configured'] = true;
  62. $sessionInfos['name'] = $this->session->getName();
  63. $sessionInfos['started'] = $this->session->isStarted();
  64. $sessionInfos['namespace'] = $this->sessionStorageKey;
  65. $sessionInfos['has_previous'] = isset($request) ? $request->hasPreviousSession() : false;
  66. $sessionInfos['storage'] = $this->sessionStorage;
  67. }
  68. $legacyKernelParameters = $event->getParameters();
  69. $legacyKernelParameters->set('session', $sessionInfos);
  70. // Deactivate session cookie settings in legacy kernel.
  71. // This will force using settings defined in Symfony.
  72. $sessionSettings = [
  73. 'site.ini/Session/CookieTimeout' => false,
  74. 'site.ini/Session/CookiePath' => false,
  75. 'site.ini/Session/CookieDomain' => false,
  76. 'site.ini/Session/CookieSecure' => false,
  77. 'site.ini/Session/CookieHttponly' => false,
  78. ];
  79. $legacyKernelParameters->set(
  80. 'injected-settings',
  81. $sessionSettings + (array)$legacyKernelParameters->get('injected-settings')
  82. );
  83. }
  84. }